我有以下代码。我尝试在所有表和参数周围放置括号,没有运气。该查询适用于Access。
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.Rows.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
修改
实际错误 - &gt; IErrorInfo.GetDescription因E_FAIL(0x80004005)
而失败答案 0 :(得分:1)
好吧,因为没有人决定回答我是靠自己找到的。
似乎使用session作为表名,Date作为参数是一个坏主意。我改变了它们并且它起作用了。