I get the following error when trying to sort my datatable by date range in a gridview:
'String was not recognized as a valid DateTime.'
AccessDateFrom and To are datepickers.
Any help please BTW I'm new to this so sorry if its a simple mistake on my part.
My code:
Private Sub ReportGen_Click(sender As System.Object, e As System.EventArgs) Handles ReportGen.Click
ProjectRef = ProjectRefInput.Text
AppNameSelect = ApplicationSelection.Text
AccessDateFrom = DateFrom.Text
AccessDateTo = DateTo.Text
'Collect the data from the system
Username = System.Security.Principal.WindowsIdentity.GetCurrent.Name
ComputerName = Environment.MachineName
AccessTime = Date.Today
AppName = My.Application.Info.AssemblyName
Try
Using cnn As New OleDbConnection(ConnString)
cnn.Open()
Using cmd As New OleDbCommand(DbUpdate, cnn)
cmd.Parameters.AddWithValue("AccessDate", AccessTime)
cmd.Parameters.AddWithValue("UserName", Username)
cmd.Parameters.AddWithValue("ComputerName", ComputerName)
cmd.Parameters.AddWithValue("AppName", AppName)
cmd.ExecuteNonQuery()
Using SelectQuery As New OleDbCommand(DbSelect, cnn)
SelectQuery.Parameters.AddWithValue("AppName", AppNameSelect)
Dim ResultsTable As New OleDb.OleDbDataAdapter(SelectQuery)
Dim DataTable As New DataTable("App_Results")
ResultsTable.Fill(DataTable)
Dim DTFilterDate As DataView = New DataView(DataTable)
DTFilterDate.RowFilter = "AccessDate >= #" & AccessDateFrom & " and AccessDate <= " & AccessDateTo & "#"
ResultsTable.Fill(DataTable)
DataGridView1.DataSource = DTFilterDate
End Using
End Using
cnn.Close()
cnn.Dispose()
End Using
Catch ex As Exception
'Unable to find or update the database
Err.Number = 2
Call ErrorCodeHandle()
End Try
RowCounter = DataGridView1.RowCount
TotalRecords.Text = RowCounter
End Sub