Question Connecting to ODBC then parsing data, then viewing in datagridview

Joined
Oct 9, 2009
Messages
14
Programming Experience
Beginner
Hey, so I am a new programmer, and I am trying to receive data from an odbc connection. I would like this data to be filtered before it comes in, and then I would like to view it in a datadgrigview. Below is some code I adapted from an example and it is getting an error that reads:


ERROR: ERROR[42000][MICROSOFT][ODBC driver for Oracle][Oracle]ORA-00936:missing expression

Could some please explain to me what this means and how to fix it?

Thank you!

The code is listed below:





Public Class Form1

Private Sub btngetemplyees_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btngetemplyees.Click
'create connection to db

Dim cn As New OdbcConnection("Dsn=dsn_here;uid=Login;server=Server;pwd=password;")


Try
Dim SQL As String
SQL = String.Format("SELECT * FROM SCORES WHERE [ID] LIKE '10'")
Dim cmd As New OdbcCommand(SQL, cn)
cmd.Connection.Open()

Dim rdr As OdbcDataReader = cmd.ExecuteReader()
If rdr.HasRows Then
With Me.DataGridView1
.Rows.Clear()
Dim ColumnCount As Integer = rdr.FieldCount
For i As Integer = 0 To ColumnCount - 1
.Columns.Add(rdr.GetName(i), rdr.GetName(i))
Next
.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.ColumnHeader
While rdr.Read
Dim objCells(ColumnCount - 1) As Object
rdr.GetValues(objCells)
.Rows.Add(objCells)
End While
End With
Else
MessageBox.Show("Not found")
Me.DataGridView1.Rows.Clear()
End If
rdr.Close()
Catch ex As Exception
MessageBox.Show("Error: " & ex.Message)
If cn.State = ConnectionState.Open Then
cn.Close()
End If
End Try
End Sub
End Class
 
I suspect it is because you have put square brackets around the ID word.. That's a Microsoftism (as in MS DBs.. Just because this is ODBC doesnt mean you should adopt MS syntax - it is an Oracle DB after all)
 
Back
Top