我一直在研究如何在我的文本框中插入值,以便我可以在我的数据库中找到它。所以我可以结果。
(Table name = rooms)
(Table contents = Roomnumber,Status,Roomtype)
(Roomnumber = 201,202,203)
(Status= Available,Occupied,Reserved)
这是我的代码:
myConnection.Open()
Dim cmd As New OleDbCommand("Select [Roomnumber] = '" & textboxt1.text & "' ,[Status] FROM [rooms]", myConnection)
Dim dt As New DataTable
dt.Load(cmd.ExecuteReader)
For Each row As DataRow In dt.Rows
Select Case row("Roomnumber").ToString()
Case "textbox1.text"
Select Case row("Status").ToString().ToLower()
Case "available"
Msgbox("hello")
Case "occupied"
Msgbox ("hi")
Case "reserved"
Msgbox ("input code")
End Select
End Select
Next
myConnection.Close()
End Sub
我希望我的Roomnumber取决于我的文本框中的内容,并在数据库中查找其状态。我的错误是我把“textbox.text”
答案 0 :(得分:0)
我得到了解决方案,我改变了我的" cmd"
的格式这是正确的代码:
myConnection.Open()
Dim cmd As New OleDbCommand("Select [Roomnumber] ,[Status] FROM [rooms] WHERE Roomnumber = " & textbox1.text & "", myConnection)
Dim dt As New DataTable
dt.Load(cmd.ExecuteReader)
For Each row As DataRow In dt.Rows
Select Case row("Roomnumber").ToString()
Case "textbox1.text"
Select Case row("Status").ToString().ToLower()
Case "available"
Msgbox("hello")
Case "occupied"
Msgbox ("hi")
Case "reserved"
Msgbox ("input code")
End Select
End Select
Next
myConnection.Close()
End Sub