我一直在尝试使用 IF/ELSE 语句来查询我的 MySQL 数据库,但似乎无法弄清楚为什么 ELSE 语句被 VB 忽略了。这是代码 - 任何帮助将不胜感激:
dbConn = New MySqlConnection("Server=" & FormLogin.ComboBoxServerIP.SelectedItem & ";Port=3306;Uid=qwertyuiop;Password=lkjhgfdsa;Database=zxcvbnm")
Dim account As Boolean = True
If dbConn.State = ConnectionState.Open Then
dbConn.Close()
End If
dbConn.Open()
Dim dbQuery As String = "SELECT * FROM customer WHERE accountNumber = '" & TextBoxSearch.Text & "';"
Dim dbData As MySqlDataReader
Dim dbAdapter As New MySqlDataAdapter
Dim dbCmd As New MySqlCommand
dbCmd.CommandText = dbQuery
dbCmd.Connection = dbConn
dbAdapter.SelectCommand = dbCmd
dbData = dbCmd.ExecuteReader
While dbData.Read()
If dbData.HasRows() = True Then
MessageBox.Show("Customer Account Found!")
Else
MessageBox.Show("No Customer Records Found! Please try again!")
dbData.Close()
End If
End While
我的意图是用将用数据库中的数据填充我的表单的代码替换“IF”子句中的消息框。