![]() 界面設(shè)計好后在button的click事件中寫入代碼如下: (在程序頂部引用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) '與數(shù)據(jù)庫建立連接 olecn.Open() olerd = olecm.ExecuteReader '循環(huán)判斷與數(shù)據(jù)庫中數(shù)據(jù)是否相同 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 整個過程就做完了簡單吧。 QQ:174453914 |
溫馨提示:喜歡本站的話,請收藏一下本站!