Error on passing Date parameter

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Meerakhanna
    New Member
    • Jul 2010
    • 1

    Error on passing Date parameter

    I am getting error when debugging a project. The error is as below,


    "FormatExceptio n was unhandled
    String was not recognized as a valid DateTime."

    Highlighting the following line

    Code:
    Me.DataTable1TableAdapter.Fill(Me.Sales.DataTable1, DateTime.ParseExact((TextBox1.Text), "MM/dd/yyyy", System.Globalization.CultureInfo.CurrentCulture), DateTime.ParseExact((TextBox2.Text), "MM/dd/yyyy", System.Globalization.CultureInfo.CurrentCulture))
    Please let me know whats the wrong??

    Thanks,
    Meera.
  • Aimee Bailey
    Recognized Expert New Member
    • Apr 2010
    • 197

    #2
    Problem is most likey that you have restrained the format in which date's are allowed to be parsed, using CurrentCulture can be tricky as the current culture is machine and location specifit. I'd reccomend using something more along the lines of:

    Code:
    Me.DataTable1TableAdapter.Fill(Me.Sales.DataTable1, DateTime.Parse((TextBox1.Text), System.Globalization.CultureInfo.InvariantCulture), DateTime.Parse((TextBox2.Text), System.Globalization.CultureInfo.InvariantCulture))
    And use a universally formatted date like '2010-07-24 14:00'.

    Best of luck!

    Comment

    Working...