Parsing from string to datetime error.
Hi,
I have tried several time to adopt msdn's parsing strings to datetime formats but they are to no avail. I am trying to extract data from sql database with a specific period with the help of the tableadapter which has this call code: select * from members where date<=@fromdate And date>=@todate Order by date.
The error i get is "String was not recognized as a valid DateTime" even if i use tryparseexact, tryparse, parseexact, cdate. The code is able to point to the date on the form but sees it as string. What could possibly be the problem?
Code:
Public Overridable Overloads Function Fill(ByVal dataTable As cmsTitheDurationDataSet4.TitheDataTable, ByVal FromDate As String, ByVal ToDate As String) As Integer
Me.Adapter.SelectCommand = Me.CommandCollection(0)
If (FromDate Is Nothing) Then
Me.Adapter.SelectCommand.Parameters(0).Value = Global.System.DBNull.Value
Else
Me.Adapter.SelectCommand.Parameters(0).Value = Date.ParseExact(FromDate, {"dd-MM-yyyy"}, Globalization.DateTimeFormatInfo.InvariantInfo, Globalization.DateTimeStyles.None)
End If
If (ToDate Is Nothing) Then
Me.Adapter.SelectCommand.Parameters(1).Value = Global.System.DBNull.Value
Else
Me.Adapter.SelectCommand.Parameters(1).Value = Date.ParseExact(ToDate, {"dd-MM-yyyy"}, Globalization.DateTimeFormatInfo.InvariantInfo, Globalization.DateTimeStyles.None)
End If
If (Me.ClearBeforeFill = True) Then
dataTable.Clear()
End If
Dim returnValue As Integer = Me.Adapter.Fill(dataTable)
Return returnValue
End Function