CSDN博客

img cn2004

登陆窗体的制作

发表于2004/9/26 17:01:00  745人阅读

文件→新建→项目 选择windows应用程序 并在窗体上添加2个label控件、2个textbox控件、2 个buton控件

界面设计好后在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)
        '与数据库建立连接
        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 

阅读全文
0 0

相关文章推荐

img
取 消
img