Results 1 to 9 of 9

Thread: [RESOLVED] String was not recognized as a valid DateTime

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Dec 2020
    Posts
    19

    Resolved [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;
    }



  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,929

    Re: String was not recognized as a valid DateTime

    What are the values in Cells[10] and Cells[8] when the issue occurs?

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Dec 2020
    Posts
    19

    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

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Dec 2020
    Posts
    19

    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

  5. #5
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,929

    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"

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,297

    Re: String was not recognized as a valid DateTime

    Quote Originally Posted by redrose4u293 View Post
    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.

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Dec 2020
    Posts
    19

    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)

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Dec 2020
    Posts
    19

    Re: String was not recognized as a valid DateTime

    i aslo timedate colum set .tostring() empty but he show same error

  9. #9
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,297

    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
  •  



Click Here to Expand Forum to Full Width