Public Class Form1
Inherits System.Windows.Forms.Form
#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 txtUserName As System.Windows.Forms.TextBox
Friend WithEvents btnLogin As System.Windows.Forms.Button
Friend WithEvents btnCancle As System.Windows.Forms.Button
Friend WithEvents txtPassWord 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.btnLogin = New System.Windows.Forms.Button
Me.btnCancle = New System.Windows.Forms.Button
Me.txtUserName = New System.Windows.Forms.TextBox
Me.txtPassWord = New System.Windows.Forms.TextBox
Me.SuspendLayout()
'
'Label1
'
Me.Label1.AutoSize = True
Me.Label1.Location = New System.Drawing.Point(24, 24)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(48, 17)
Me.Label1.TabIndex = 0
Me.Label1.Text = "用户名:"
'
'Label2
'
Me.Label2.AutoSize = True
Me.Label2.Location = New System.Drawing.Point(24, 48)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(35, 17)
Me.Label2.TabIndex = 1
Me.Label2.Text = "密码:"
'
'btnLogin
'
Me.btnLogin.Location = New System.Drawing.Point(32, 88)
Me.btnLogin.Name = "btnLogin"
Me.btnLogin.TabIndex = 2
Me.btnLogin.Text = "登录"
'
'btnCancle
'
Me.btnCancle.Location = New System.Drawing.Point(136, 88)
Me.btnCancle.Name = "btnCancle"
Me.btnCancle.TabIndex = 3
Me.btnCancle.Text = "取消"
'
'txtUserName
'
Me.txtUserName.Location = New System.Drawing.Point(80, 16)
Me.txtUserName.Name = "txtUserName"
Me.txtUserName.TabIndex = 4
Me.txtUserName.Text = ""
'
'txtPassWord
'
Me.txtPassWord.Location = New System.Drawing.Point(80, 40)
Me.txtPassWord.Name = "txtPassWord"
Me.txtPassWord.PasswordChar = Microsoft.VisualBasic.ChrW(42)
Me.txtPassWord.TabIndex = 5
Me.txtPassWord.Text = ""
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(240, 127)
Me.Controls.Add(Me.txtPassWord)
Me.Controls.Add(Me.txtUserName)
Me.Controls.Add(Me.btnCancle)
Me.Controls.Add(Me.btnLogin)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.Label1)
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
Me.MaximizeBox = False
Me.MinimizeBox = False
Me.Name = "Form1"
Me.Text = "登录"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub btnCancle_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancle.Click
Me.Close()
End Sub
Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click
If Me.txtUserName.Text.Trim.Length = 0 Or Me.txtPassWord.Text.Trim.Length = 0 Then
MsgBox("请输入用户名或密码")
Exit Sub
End If
Dim conString As String = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA Source=D:\Inetpub\wwwroot\WebApplication1\Database\Test.mdb"
Dim conn As New OleDb.OleDbConnection(conString)
Dim comm As New OleDb.OleDbCommand("SELECT UserName, PassWord FROM UserInfo WHERE UserName = '" & Me.txtUserName.Text & "'", conn)
Try
conn.Open()
Dim dr As OleDb.OleDbDataReader = comm.ExecuteReader()
If dr.HasRows Then
dr.Read()
If dr.Item("PassWord").ToString = Me.txtPassWord.Text Then
MsgBox("登录成功")
Else
MsgBox("登录失败")
End If
End If
dr.Close()
Catch ex As Exception
MsgBox(ex.ToString)
Finally
If conn.State = ConnectionState.Open Then conn.Close()
conn.Dispose()
comm.Dispose()
End Try
End Sub
End Class
http://www.80diy.com/home/20051101/10/4363173.html或参考
http://zhidao.baidu.com/question/8176586.html