0

Try

MySqlConn.Open()

        Dim Query = "Select * From venuesdb.cost where EventDate  >= ('" & DateTimePicker1.Text & "') AND =< ('" & DateTimePicker2.Text & "')"
        Command = New MySqlCommand(Query, MySqlConn)
        SQLDataAdapter.SelectCommand = Command
        SQLDataAdapter.Fill(DatabaseDatSet)
        Bindsource.DataSource = DatabaseDatSet
        DataGridView1.DataSource = Bindsource
        SQLDataAdapter.Update(DatabaseDatSet)
        MySqlConn.Close()

    Catch ex As Exception
        MessageBox.Show(ex.Message)

    End Try
    MySqlConn.Dispose()

I keep getting error saying that there is a SQL error here '>= ('" & DateTimePicker2 & " ')'

potashin
  • 44,205
  • 11
  • 83
  • 107

2 Answers2

2

Your syntax is incorrect, you can either use between without <= and >=(mind symbol sequence in the operators):

Dim Query = "select *
             from venuesdb.cost
             where EventDate  between '" & DateTimePicker1.Text & "' AND '" & DateTimePicker2.Text & "'"

or specify field each time you specify condition:

Dim Query = "select *
             from venuesdb.cost
             where EventDate  >= '" & DateTimePicker1.Text & "' AND EventDate <= '" & DateTimePicker2.Text & "'"
potashin
  • 44,205
  • 11
  • 83
  • 107
1

You missed a EventDate in your query. Change your code to this:

Dim Query = "Select * From venuesdb.cost where EventDate  >= ('" & DateTimePicker1.Text & "') AND EventDate =< ('" & DateTimePicker2.Text & "')"

Also, you should use parameters in your query to avoid SQL-injection attacks. You can read more about it in this SO question.

Community
  • 1
  • 1
user707727
  • 1,287
  • 7
  • 16