vb.net 登录access源代码【原创】

简介:
 
在窗体中加入两个txt框,两个按钮。界面设计如上图所示。
数据库中设计access表,adminuser,表中创建username、passwrod两个文本字段。access文件名称为my.mdb.其源代码如下:
Imports System.Data
Imports System.Data.OleDb
Public Class LoginFrm
    Inherits System.Windows.Forms.Form
    Public ADOcmd As OleDbDataAdapter
    Public ds As DataSet = New DataSet
    Public mytable As Data.DataTable
    Public myrow As Data.DataRow
    Public rownumber As Integer
    Public searchsql As String
    Public cmd As OleDbCommandBuilder
    Public Function ExecuteSQL(ByVal SQL As String, ByVal table As String)
        ADOcmd = New OleDbDataAdapter(SQL, "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Application.StartupPath() & "\my.mdb")
        ADOcmd.Fill(ds, table)
        mytable = ds.Tables.Item(0)
        rownumber = 0
        myrow = mytable.Rows.Item(rownumber)
    End Function
#Region " Windows 窗体设计器生成的代码 "
    Public Sub New()
        MyBase.New()
        '该调用是 Windows 窗体设计器所必需的。
        InitializeComponent()
        '在 InitializeComponent() 调用之后添加任何初始化
    End Sub
    '窗体重写 dispose 以清理组件列表。
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub
    'Windows 窗体设计器所必需的
    Private components As System.ComponentModel.IContainer
    '注意: 以下过程是 Windows 窗体设计器所必需的
    '可以使用 Windows 窗体设计器修改此过程。
    '不要使用代码编辑器修改它。
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents btn_ok As System.Windows.Forms.Button
    Friend WithEvents btn_cancel As System.Windows.Forms.Button
    Friend WithEvents Txt_Username As System.Windows.Forms.TextBox
    Friend WithEvents Txt_pwd As System.Windows.Forms.TextBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.Label1 = New System.Windows.Forms.Label
        Me.Label2 = New System.Windows.Forms.Label
        Me.Txt_Username = New System.Windows.Forms.TextBox
        Me.Txt_pwd = New System.Windows.Forms.TextBox
        Me.btn_ok = New System.Windows.Forms.Button
        Me.btn_cancel = New System.Windows.Forms.Button
        Me.SuspendLayout()
        '
        'Label1
        '
        Me.Label1.AutoSize = True
        Me.Label1.Location = New System.Drawing.Point(48, 32)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(54, 17)
        Me.Label1.TabIndex = 0
        Me.Label1.Text = "用户名:"
        '
        'Label2
        '
        Me.Label2.AutoSize = True
        Me.Label2.Location = New System.Drawing.Point(48, 64)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(54, 17)
        Me.Label2.TabIndex = 1
        Me.Label2.Text = "密  码:"
        '
        'Txt_Username
        '
        Me.Txt_Username.Location = New System.Drawing.Point(112, 32)
        Me.Txt_Username.Name = "Txt_Username"
        Me.Txt_Username.Size = New System.Drawing.Size(96, 21)
        Me.Txt_Username.TabIndex = 2
        Me.Txt_Username.Text = ""
        '
        'Txt_pwd
        '
        Me.Txt_pwd.Location = New System.Drawing.Point(112, 64)
        Me.Txt_pwd.Name = "Txt_pwd"
        Me.Txt_pwd.PasswordChar = Microsoft.VisualBasic.ChrW(42)
        Me.Txt_pwd.Size = New System.Drawing.Size(96, 21)
        Me.Txt_pwd.TabIndex = 3
        Me.Txt_pwd.Text = ""
        '
        'btn_ok
        '
        Me.btn_ok.Location = New System.Drawing.Point(64, 104)
        Me.btn_ok.Name = "btn_ok"
        Me.btn_ok.Size = New System.Drawing.Size(48, 24)
        Me.btn_ok.TabIndex = 4
        Me.btn_ok.Text = "登录"
        '
        'btn_cancel
        '
        Me.btn_cancel.Location = New System.Drawing.Point(160, 104)
        Me.btn_cancel.Name = "btn_cancel"
        Me.btn_cancel.Size = New System.Drawing.Size(48, 24)
        Me.btn_cancel.TabIndex = 5
        Me.btn_cancel.Text = "关闭"
        '
        'LoginFrm
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
        Me.ClientSize = New System.Drawing.Size(296, 158)
        Me.Controls.Add(Me.btn_cancel)
        Me.Controls.Add(Me.btn_ok)
        Me.Controls.Add(Me.Txt_pwd)
        Me.Controls.Add(Me.Txt_Username)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.Label1)
        Me.MaximizeBox = False
        Me.MinimizeBox = False
        Me.Name = "LoginFrm"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "登录"
        Me.ResumeLayout(False)
    End Sub
#End Region
    Private Sub btn_cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_cancel.Click
        Me.Close()
    End Sub
    Private Sub btn_ok_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_ok.Click
        '定义 
        Dim tablename As String
        tablename = "adminuser"
        Dim SearchSQL As String
        SearchSQL = "select username,password from adminuser where username='" & Txt_Username.Text & "'"
        Try
            ExecuteSQL(SearchSQL, tablename)
            If myrow.Item(1) = Txt_pwd.Text Then
                MsgBox("成功登陆")
                Dim FormMain As New FormMain
                FormMain.Show()
                Me.Hide()
            Else
                MsgBox("密码不正确!", vbOKOnly + vbExclamation, "警告")
                Exit Sub
            End If
        Catch
            MsgBox("無此用戶!", vbOKOnly + vbExclamation, "警告")
        End Try
    End Sub
    Private Sub LoginFrm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    End Sub
    Private Sub Txt_pwd_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Txt_pwd.KeyDown
        If e.KeyCode = Keys.Enter Then
            btn_ok.Visible = True
            btn_ok.Focus()
        End If
    End Sub
    Private Sub Txt_Username_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Txt_Username.KeyDown
        If e.KeyCode = Keys.Enter Then
            Txt_pwd.Focus()
        End If
    End Sub
End Class

 本文转自 simeon2005 51CTO博客,原文链接:http://blog.51cto.com/simeon/94357

相关文章
|
存储 安全 .NET
ASP.NET Core Identity 实战(2)——注册、登录、Claim
上一篇文章(ASP.NET Core Identity Hands On(1)——Identity 初次体验)中,我们初识了Identity,并且详细分析了AspNetUsers用户存储表,这篇我们将一起学习Identity 默认生成的样板代码的注册与登陆过程 注册/Register 打开Accou...
2437 0
|
2月前
|
安全 Java 网络安全
Android远程连接和登录FTPS服务代码(commons.net库)
很多文章都介绍了FTPClient如何连接ftp服务器,但却很少有人说如何连接一台开了SSL认证的ftp服务器,现在代码来了。
78 2
|
开发框架 .NET 数据安全/隐私保护
【ASP.NET】通过Web.config实现登录
本文是通过authentication(认证访问者) 和 authorization( 访问权限),来实现一个简单的判断用户账号密码是否正确。
118 0
【ASP.NET】通过Web.config实现登录
|
JavaScript 开发工具 数据安全/隐私保护
使用.net 和Selenium模拟百度登录
使用自动化技术来模拟下百度登录
225 0
使用.net 和Selenium模拟百度登录
|
Web App开发 前端开发 .NET
ASP.NET Core 一步步搭建个人网站(2)_一键部署和用户注册登录
俗话说,磨刀不费砍柴工。为了更方便的进行项目管理,我们先将个人网站项目配置一下,满足以下2个目标: VS2017中支持Git存储库,绑定Github项目,实现本地VS程序与线上Github一键代码提交和同步; 搭建服务器FTP站点,VS2017中配置一键部署网站文件到服务器; 有了以上的配置,我们可以不用每次拉取和同步我们的程序到Github中,也不用每次在本地发布,拷贝服务器,我们只用在VS2017中简单的一键同步到Github或网站服务器。
1594 0
|
.NET 数据安全/隐私保护 索引
ASP.NET Core 登录登出 - ASP.NET Core 基础教程 - 简单教程,简单编程
原文:ASP.NET Core 登录登出 - ASP.NET Core 基础教程 - 简单教程,简单编程 ASP.NET Core 登录登出 上一章节我们总算完善了注册的功能,而且也添加了一个用户,现在,我们是时候继续完善登录登出功能了。
1673 0
|
.NET 开发框架 数据格式
ASP.NET CORE系列【四】基于Claim登录授权
原文:ASP.NET CORE系列【四】基于Claim登录授权 介绍  关于什么是Claim?   可以看看其他大神的文章:  http://www.cnblogs.com/jesse2013/p/aspnet-identity-claims-based-authentication-and-owin.
3210 0
.NET webbrowser自动填充登录
HtmlElement name = webBrowser1.Document.GetElementById("ctl00$content$loginname"); if (name != null) name.
848 0
|
JSON 前端开发 .NET
ASP.NET Core 一步步搭建个人网站(4)_主页和登录验证
上章节我们已经定制好动态配置的菜单,用户登录网站的第一步就是进入首页内容,那我们先搭建一下我们的首页内容。想着自己的网站内容主要是个人博客类型,所以,首页就展示博主本人的一些基本信息吧,哈哈。当然,做成静态的界面很简单,直接将信息填进html中就行了,基本没有什么技术含量,那我们这里要做成可配置的:将个人信息配置在json文件中(也可以存储在数据库,考虑信息内容结构的不可预期性和易变性,这里不采用数据库保存)。
2131 0