I need to pick from two date ranges from a couple of datetimepickers in the form. Then when I run the query, it should clear the current data in the listview, run the query, then re-populate the listview.
I use the same code to simply load the listview, and similar code to delete from the MySQL and reload the listview and everything works great. But this one isn't working- it doesn't generate any errors, but also doesn't sort either.
Can someone take a look and double check it for me? I suspect something is wrong.
Public Sub SortByDateTraining() MySqlConnection.ConnectionString = x.urlMySQLDatabase1 Try MySqlConnection.Open() Catch ex As Exception MsgBox("It looks like your internet is taking a second to pull the required data... ") End Try ' Clear the items in the listview to reload them from the query below frmMain.lvTraining.Items.Clear() Dim sqlQuery As String = "SELECT * FROM Training WHERE Training.startdate = '" & frmMain.dtpTrainingStart.Text & "' AND Training.enddate = '" & frmMain.dtpTrainingEnd.Text & "'" Dim sqlAdapter As New MySqlDataAdapter Dim sqlCommand As New MySqlCommand Dim TABLE As New DataTable With sqlCommand .CommandText = sqlQuery .Connection = MySqlConnection End With With sqlAdapter .SelectCommand = sqlCommand .Fill(TABLE) End With For i = 0 To TABLE.Rows.Count - 1 With frmMain.lvTraining .Items.Add(TABLE.Rows(i)("number")) With .Items(.Items.Count - 1).SubItems .Add(TABLE.Rows(i)("startdate")) .Add(TABLE.Rows(i)("enddate")) .Add(TABLE.Rows(i)("location")) .Add(TABLE.Rows(i)("traininghours")) .Add(TABLE.Rows(i)("trainingtype")) .Add(TABLE.Rows(i)("trainingname")) .Add(TABLE.Rows(i)("certification")) .Add(TABLE.Rows(i)("expiration")) End With End With Next CalculateTrainingHours() MySqlConnection.Close() End Sub