SQL IErrorInfo.GetDescription error.Brackets not working
I have the following code. I tried putting brackets around all the tables and parameters with no luck. The query works in Access though.
Dim cn As OleDbConnection
Dim cmd As OleDbCommand
Dim str As String
Dim dr As OleDbDataReader
DataGridView1.Rows.Clear()
Try
cn = New OleDbConnection("Provider=microsoft.Jet.OLEDB.4.0;Data Source=G:\Sean\BMSBonder3_0.mdb;")
cn.Open()
str = "Select [Session.BonderIdentifier], [Bonder.ID], [Session.UserName], [Session.Login], [Session.Logout] From [Session] Left Join " _
& " Bonder On Session.Login = [Bonder.Date] Where [BasicLogin] >= ? AND [BasicLogin] <= ? AND BonderIdentifier = '?'"
cmd = New OleDbCommand(str, cn)
cmd.Parameters.AddWithValue("Start", MonthCalendar1.SelectionStart)
cmd.Parameters.AddWithValue("End", MonthCalendar1.SelectionEnd)
cmd.Parameters.AddWithValue("BID", ListBox1.SelectedItem)
dr = cmd.ExecuteReader
While dr.Read()
If dr.Item(0).ToString <> "" Then
DataGridView1.Ro开发者_StackOverflow社区ws.Add(dr.Item(0), dr.Item(1), dr.Item(2), dr.Item(3), dr.Item(4))
End If
End While
DataGridView1.Sort(DataGridView1.Columns.Item("Login_Time"), System.ComponentModel.ListSortDirection.Ascending)
dr.Close()
cn.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
Edit:
Actual error-> IErrorInfo.GetDescription failed with E_FAIL(0x80004005)
Well since no one decided to answer I found it on my own.
Seems that using session as a table name and Date as a parameter was a bad idea. I changed them and it worked.
精彩评论