我的代码出了什么问题。我想要的是,如果我点击rdbNormal
(一个RadioButton),然后选择" A"在cmbBuilding
(一个ComboBox)中,所有RoomNo都有房型"正常"和建筑" 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()
答案 0 :(得分:1)
在您的查询中
... and RoomType = Normal
由于未引用Normal
,因此它被视为参数占位符。如果你想匹配文字值,那么在它周围加上引号:
... and RoomType = 'Normal'