2015-09-25 48 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

謝謝:)現在它的工作 –

相關問題