(在程序顶部引用Imports System.Data.OleDb) Private Sub BOk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BOk.Click '定义 Dim olecn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Data.mdb") Dim olecm As New OleDbCommand("select * from Login", olecn) Dim olead As New OleDbDataAdapter Dim olerd As OleDbDataReader Dim pd As Boolean = False '定义boolean为后面错误处理使用 Dim i As Integer olecm = New OleDbCommand("select * from Login", olecn) '与数据库建立连接 olecn.Open() olerd = olecm.ExecuteReader '循环判断与数据库中数据是否相同 Do While olerd.Read() For i = 0 To olerd.FieldCount - 1 If Trim(TUser.Text) = (olerd.Item("帐号")) And Trim(TPassword.Text) = (olerd.Item("密码")) Then MsgBox("成功登陆") pd = True Exit Sub End If Next Loop TUser.Text = "" TPassword.Text = "" TUser.Focus() olerd.Close() olecn.Close() End Sub |