我遇到错误代码:
没有为一个或多个必需参数提供值。
在我程序的loadTransactions
上。
我尝试解决了很多次,但未能解决问题。
Private Sub loadTransactions(ByVal transactionid As Integer)
Dim dt As New DataTable
Using cnn As New OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0; Data Source=mydataX.mdb;")
Using cmd As New OleDbCommand(
"SELECT I.cid as [ID], c.CheckerName as Ite, " &
"I.CompanyName, I.ModelName, I.TrackChecker as [CheckerName], I.Date, I.Category, I.PIC, I.OtherPIC, I.Remarks" &
" FROM tbl_Info I left join tbl_checker c on c.cid = I.checkercid WHERE I.checkercid = @transactionID ORDER BY I.cid", cnn)
' "FROM tbl_Info I left join tbl_checker c on c.cid = I.checkercid where I.checkercid = " & transactionid & " ORDER BY I.cid", cnn)
cmd.Parameters.Add("transactionID", OleDbType.Integer).Value = transactionid
cnn.Open()
dt.Load(cmd.ExecuteReader)
End Using
End Using
DataGridView1.DataSource = dt
End Sub
这是我在程序中使用的另一个代码
Private Sub loadTransactions(ByVal transactionid As Integer)
If Not cnn.State = ConnectionState.Open Then
cnn.Open()
End If
Dim da As New OleDb.OleDbDataAdapter(
"SELECT I.cid as [ID], c.CheckerName as item_name, " &
"I.CompanyName, I.ModelName, I.TrackChecker as [CheckerName], I.Date, I.Category, I.PIC, I.OtherPIC, I.Remarks" &
"FROM tbl_Info I left join tbl_checker c on c.cid = I.checkercid where I.checkercid = " &
transactionid & " ORDER BY I.cid", cnn)
Dim dt As New DataTable
da.Fill(dt)
Me.DataGridView1.DataSource = dt
Me.DataGridView1.Columns("item_name").HeaderText = "CheckerName"
'close connection
cnn.Close()
End Sub