给定一个或多个必需参数没有值

时间:2015-09-25 10:18:02

标签: ms-access-2010 vb.net-2010

我的代码出了什么问题。我想要的是,如果我点击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()

1 个答案:

答案 0 :(得分:1)

在您的查询中

... and RoomType = Normal

由于未引用Normal,因此它被视为参数占位符。如果你想匹配文字值,那么在它周围加上引号:

... and RoomType = 'Normal'