Scott Palmer
asked on
SQL syntax in VB.net
I am trying to run an SQL query in VB.NET and I am having problems with the syntax. Below is the code and I have attached the error.
adoConn.CursorLocation = CursorLocationEnum.adUseClient
adoConn.Open("Driver={MySQL ODBC 5.2 ANSI Driver};" & "server=" & lServer & ";user=spalmer" &
";password=mypassword;database=daily_reports")
rsCodeLookup.Open("SELECT * FROM 100_report WHERE RPT_DATE > date(now()) - 300", adoConn, CursorTypeEnum.adOpenStatic, LockTypeEnum.adLockReadOnly)
rsCodeLookup.ActiveConnection = Nothing
SQL-Error.docx
Sorry, VB
Dim sqlConnection1 As New SqlConnection("Driver={MySQL ODBC 5.2 ANSI Driver};server=lServer;user=spalmer;password=mypassword;database=daily_reports")
Dim cmd As New SqlCommand
Dim reader As SqlDataReader
cmd.CommandText = "SELECT * FROM 100_report WHERE RPT_DATE > date(now()) - 300"
cmd.CommandType = CommandType.Text
cmd.Connection = sqlConnection1
sqlConnection1.Open()
reader = cmd.ExecuteReader()
' Data is accessible through the DataReader object here.
sqlConnection1.Close()
ASKER
Thanks, but I was hoping to use my current code as much as possible.
This code below worked, but the query was too large to so tried to filter with the date to get a smaller result.
rsCodeLookup.Open("SELECT * FROM 100_report", adoConn, CursorTypeEnum.adOpenStati c, LockTypeEnum.adLockReadOnl y)
It was only when I added the where clause that I had problems.
This code below worked, but the query was too large to so tried to filter with the date to get a smaller result.
rsCodeLookup.Open("SELECT * FROM 100_report", adoConn, CursorTypeEnum.adOpenStati
It was only when I added the where clause that I had problems.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Had to rework the DATE_ADD order, but got it to work. Thanks.
Open in new window