当我尝试连接到我的数据库时出错。 我想要做的是检查我的DataBase中的同一行是否有姓名和姓氏
离。 Id_ 1 Michael Dawn
我有2个文本框,如果包含: Textbox1 - 迈克尔 Textbox2 - 黎明
然后这是一场积极的比赛
我收到错误:
需要一些帮助,谢谢 这是我的代码
导入MySql.Data 导入MySql.Data.MySqlClient 公共类Form2
Dim dbCon As MySqlConnection
Dim strQuery As String = ""
Dim SQLCmd As MySqlCommand
Dim DR As MySqlDataReader
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'just a message
MsgBox(" You are searching for the users: " & vbCrLf & "Name: " & TextBox1.Text & vbCrLf & "Surname: " & TextBox2.Text)
' connecting to the database
dbCon = New MySqlConnection("Server = localhost, Database = users, Uid = root, Pwd = password")
strQuery = "SELECT users.name, users.surname" & _
"WHERE users.name = '" + TextBox1.Text + "'AND password = '" + TextBox2.Text + "'"
SQLCmd = New MySqlCommand(strQuery, dbCon)
'Database open
Try
dbCon.Open()
DR = SQLCmd.ExecuteReader
If DR.HasRows = 0 Then
MsgBox("Not a match", MsgBoxStyle.Critical)
Else
MsgBox("You guessed the correct name: " & TextBox1.Text & "and the surname: " & TextBox2.Text)
End If
'Close
DR.Close()
dbCon.Close()
Catch ex As Exception
MsgBox("Failure to communicate " & vbCrLf & vbCrLf & ex.Message)
End Try
End Sub
结束班级