没有给定一个或多个必需参数的值
No value given one or more required parameters
我的代码有什么问题。我想要的是,如果我单击 rdbNormal
(单选按钮),然后在 cmbBuilding
(组合框)中单击 select "A",则所有 RoomNo 的房间类型为 "normal" 并且将显示建筑物 "A"。
这是我的代码
Try
cn.Open()
If rdbNormal.Checked = True Then
Dim DataSet As New DataSet
Dim DataTable As New DataTable
Dim DataAdapter As New OleDbDataAdapter("SELECT * FROM RoomTable Where Building = '" & cmbBuilding.Text & "' and RoomType = Normal ", cn)
DataAdapter.Fill(DataTable)
If DataTable.Rows.Count > 0 Then
With cmbRoomNo
.Items.Clear()
For i As Integer = 0 To DataTable.Rows.Count - 1
.Items.Add(DataTable.Rows(i).Item(3))
Next
.SelectedIndex = -1
End With
End If
DataTable.Dispose()
DataAdapter.Dispose()
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
cn.Close()
在您的查询中您有
... and RoomType = Normal
由于未引用 Normal
,因此它被视为参数占位符。如果您想匹配文字值,请在其周围加上引号:
... and RoomType = 'Normal'
我的代码有什么问题。我想要的是,如果我单击 rdbNormal
(单选按钮),然后在 cmbBuilding
(组合框)中单击 select "A",则所有 RoomNo 的房间类型为 "normal" 并且将显示建筑物 "A"。
这是我的代码
Try
cn.Open()
If rdbNormal.Checked = True Then
Dim DataSet As New DataSet
Dim DataTable As New DataTable
Dim DataAdapter As New OleDbDataAdapter("SELECT * FROM RoomTable Where Building = '" & cmbBuilding.Text & "' and RoomType = Normal ", cn)
DataAdapter.Fill(DataTable)
If DataTable.Rows.Count > 0 Then
With cmbRoomNo
.Items.Clear()
For i As Integer = 0 To DataTable.Rows.Count - 1
.Items.Add(DataTable.Rows(i).Item(3))
Next
.SelectedIndex = -1
End With
End If
DataTable.Dispose()
DataAdapter.Dispose()
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
cn.Close()
在您的查询中您有
... and RoomType = Normal
由于未引用 Normal
,因此它被视为参数占位符。如果您想匹配文字值,请在其周围加上引号:
... and RoomType = 'Normal'