2015-09-25 96 views
0

我的代码有什么问题。我想要的是,如果我点击rdbNormal(RadioButton),然后在cmbBuilding(ComboBox)中选择“A”,则将显示房型为“normal”且建筑物为“A”的所有RoomNo。 这里是我的代码没有给出一个或多个必需参数的值

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() 

回答

1

在你查询你有

... and RoomType = Normal 

由于Normal没有加引号它被视为一个参数占位符。如果你想匹配文字值,然后把报价周围:

... and RoomType = 'Normal' 
+0

谢谢:)现在它的工作 –

相关问题