Imports System.Data.SqlClient
Public Class frmLogin
Private Sub frmLogin_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
txtUsername.Text = "张三"
txtPwd.Text = "123"
End Sub
Private Sub frmLogin_Disposed(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Disposed
Me.Close()
End Sub
Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
Dim conn As SqlConnection = GetConnection()
conn.Open()
Dim strSql As String = _
"Select * From 用户表 Where username='{0}' and password='{1}'"
strSql = String.Format(strSql, txtUsername.Text, txtPwd.Text)
Dim da As New SqlDataAdapter(strSql, conn)
Dim dt As New DataTable
da.Fill(dt)
conn.Close()
If dt.Rows.Count <> 0 Then
username = txtUsername.Text
password = txtPwd.Text
frmMain.Show()
Me.Hide()
Else
MsgBox("用户不存在!")
End If
End Sub
Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
Me.Close()
End Sub
End Class