Imports System.Data.OleDb
Public Class 实验一
    Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click
        Dim str As String = "Provider= Microsoft.Jet.OLEDB.4.0;" & _
       "Data Source =" & TextBox3.Text   ' 定义连接字符串
        Dim Conn As New OleDbConnection(str)  ' 创建OleDbConnection对象
        Conn.Open()     ' 打开数据库连接
        Dim selSql As String = "Select * From userinfo where username='" & TextBox1.Text & "'  and userpwd='" & TextBox2.Text & "'"
        Dim command As New OleDbCommand(selSql, Conn) '建立Command对象
        Dim dr As OleDbDataReader   ' 创建OleDbDataReader对象
        dr = command.ExecuteReader  ' 执行命令
        If dr.Read() Then  ' dr对象记录指针移动到下一条记录，是否有查询出的记录
            MsgBox(TextBox1.Text & "用户成功登录！", CType(MsgBoxStyle.Information + MsgBoxStyle.OkOnly, MsgBoxStyle), "登录成功")
        Else
            MsgBox("用户名或密码输入有误，请重新输入！", CType(MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, MsgBoxStyle), "登录失败")
            TextBox1.Text = ""
            TextBox2.Text = ""
            TextBox1.Focus()
        End If
        dr.Close()      ' 关闭OleDbDataReader对象
        Conn.Close()     '关闭数据库连接
    End Sub

    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
        End
    End Sub
End Class