-
Feb 5th, 2021, 11:36 PM
#1
Thread Starter
Junior Member
[RESOLVED] String was not recognized as a valid DateTime
string updatestockquery = string.Format("update StockTable set Quantity = Quantity + '{0}', SaleUnitPrice = '{1}', PurchaseUnitPrice = '{2}', ExpiryDate= '{3}', MfturDate = '{4}', StockTrasholdQty = '{5}' where ProductID = '{6}'",
purchaseqty, Convert.ToString(productrow.Cells[7].Value).Trim(), Convert.ToString(productrow.Cells[6].Value).Trim(), Convert.ToString(productrow.Cells[11].Value).Trim(), Convert.ToDateTime(productrow.Cells[10].Value).ToString("yyyyMMdd HHmmss"), Convert.ToDateTime(productrow.Cells[8].Value).ToString("yyyyMMdd HHmmss"), Convert.ToString(productrow.Cells[2].Value).Trim());
bool productupdateresult = DatabaseAccess.Update(updatestockquery);
if (productupdateresult == false)
{
Accounts.DeletePurchaseInvoiceDetails(SupplierInvoiceID);
Accounts.DeleteTransectionDetails(invoiceno);
break;
}
|
-
Feb 6th, 2021, 02:48 AM
#2
Re: String was not recognized as a valid DateTime
What are the values in Cells[10] and Cells[8] when the issue occurs?
-
Feb 6th, 2021, 02:56 AM
#3
Thread Starter
Junior Member
Re: String was not recognized as a valid DateTime
values in the cells it dates of two month 06/02/2021 to 21/03/2021
-
Feb 6th, 2021, 03:04 AM
#4
Thread Starter
Junior Member
Re: String was not recognized as a valid DateTime
i also tried the change the date formate and put cell 10 or 8 value .tostring but it also show same error
-
Feb 6th, 2021, 04:10 AM
#5
Re: String was not recognized as a valid DateTime
Assuming that the values that end up in updatestockquery look OK to you, try using a different format for the date values.
Instead of:
"yyyyMMdd HHmmss"
try:
"yyyy-MM-dd HHmmss"
or:
"yyyy-MM-dd HH:mm:ss"
-
Feb 6th, 2021, 04:55 AM
#6
Re: String was not recognized as a valid DateTime
Originally Posted by redrose4u293
values in the cells it dates of two month 06/02/2021 to 21/03/2021
What is the culture on your machine? If it is US then that second value is not valid and the first will be interpreted incorrectly.
-
Feb 6th, 2021, 05:55 AM
#7
Thread Starter
Junior Member
Re: String was not recognized as a valid DateTime
can you please explain me how can i resolve this issuse Beacuse i can change the all setting time and date dd-MMM-yy (my time and date setting)
-
Feb 6th, 2021, 06:55 AM
#8
Thread Starter
Junior Member
Re: String was not recognized as a valid DateTime
i aslo timedate colum set .tostring() empty but he show same error
-
Feb 6th, 2021, 07:04 AM
#9
Re: String was not recognized as a valid DateTime
Did you ever consider answering the question I asked? If you want people to help you and they ask for information to do that, it's a good idea to provide it. You can call Date.ParseExact or TryParseExact and specify the format but you shouldn't have to if the input is in the right format for your culture.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|