hello, i am currently writing a program that will requires to read from a mySQL database and write the data to a Excel file. I have the writting to the excel file, but my select statement gives me a sql syntax eror. my code looks like this :
It's the last line that gives me the syntax error. I used a message box to show me the query before i used it to make sure it's exactly how i wanted it. and i also put that query into access to see if that gave me and syntax error and it ran perfectly. I was hoping maby some had an idea to get it to work??
VB.NET:
Dim strSQL As String 'Select statment
Dim startDate As String 'start date - 1 string for sql statment
Dim endDate As String 'end date - 1 string for sql statment
startDate = startDateTimePicker.Value.AddDays(-1).ToString("MM/dd/yy")
endDate = endDateTimePicker.Value.ToString("MM/dd/yy")
strSQL = "SELECT Format(wab_answers.answerTime,'mm/dd/yyyy') as [Date], Count(Format(wab_answers.answerTime,'mm/dd/yyyy')) as [Count] FROM wab_answers WHERE wab_answers.answerTime > #" + startDate + " 11:59:59 PM# And wab_answers.answerTime < #" + endDate + " 11:59:59 PM# And wab_answers.wabScreen = 1 OR wab_answers.wabScreen = 2 GROUP BY Format(wab_answers.answerTime,'mm/dd/yyyy');"
If (MessageBox.Show(strSQL, "TEST", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.No) Then
End
End If
Dim bdwsmtCon As New Odbc.OdbcConnection("Driver={MySQL ODBC 3.51 Driver};server=192.168.2.5;port=3306;database=bdwsmt;option=3;pwd=password;uid=username;")
Dim bdwsmtCommande As New Odbc.OdbcCommand(strSQL, bdwsmtCon)
bdwsmtCommande.Connection.Open()
Dim bdwsmtReader As Odbc.OdbcDataReader = bdwsmtCommande.ExecuteReader(CommandBehavior.CloseConnection)