16,555
社区成员
发帖
与我相关
我的任务
分享
Imports MySql.Data.MySqlClient
Public Class Form1
'数据连接对象
Dim con As New MySqlConnection
Dim comm As New MySqlCommand
'登录数据
Dim user As String
Dim pas As String
REM 登录功能
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'提取输入条件
user = Username.Text
pas = Password.Text
Debug.Print(user + Chr(10) + pas)
'查询语句
Dim sql As String = "select * from userinfo where userName = '" & user & "'"
Debug.Print(sql)
comm = New MySqlCommand(sql, con)
Dim da = New MySqlDataAdapter(sql, con)
Dim dt = New DataSet()
da.Fill(dt, "sql")
MsgBox(dt.Tables("sql").Rows.Count)
con.Close()
End Sub
'取消功能
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Username.Text = ""
Password.Text = ""
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'数据连接
con.ConnectionString = "Server=127.0.0.1;UserID=root;Password=12345;Database=candy"
con.Open()
'数据连接状态判别
If con.State = ConnectionState.Open Then
Debug.Print("数据库连接成功!")
Else
Debug.Print("数据库连接失败!")
End If
End Sub
End Class