Imports MySql.Data.MySqlClient
Imports MySql.Data
Public Class Form1
Dim dbcon As New MySqlConnection("Data Source=VINCENT-PC\SQLEXPRESS;Initial Catalog=Group1;Integrated Security=True")
Dim sqlcmd As String
Dim mysqlcmd As MySqlCommand
Dim dr As MySqlDataReader
Private Sub btnSearch_Click(sender As System.Object, e As System.EventArgs) Handles btnSearch.Click
Try
sqlcmd = "Select * from Sample1 where num=" + txtname.Text
mysqlcmd = New MySqlCommand(sqlcmd, dbcon)
dbcon.Open()
dr = mysqlcmd.ExecuteReader
While dr.Read
txtfname = dr.Item("fname")
txtlname = dr.Item("lname")
End While
dr.Close()
dbcon.Close()
Catch ex As Exception
MsgBox("Error: " & vbCrLf & vbCrLf & vbCrLf & ex.Message)
End Try
End Sub
End Class
这是我写的代码,但它似乎没有连接到我的数据库,请帮助我并提前谢谢你