Imports System.Data.SqlClient
Imports System.Data
Public Class Login
Public t As New DataTable
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
TextBox1.Text = ""
TextBox2.Text = ""
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim sqlstr As String
If TextBox1.Text <> "" And TextBox2.Text = "" Then
MsgBox("请输入口令!", , "提示")
ElseIf TextBox1.Text = "" And TextBox2.Text <> "" Then
MsgBox("请输入用户名!", , "提示")
ElseIf TextBox1.Text = "" And TextBox2.Text = "" Then
MsgBox("请输入用户名和口令!", , "提示")
Else
Call DBopen()
'sqlstr = "select * from admin where username=@name and password=@pwd"
sqlstr = "select * from admin where userid='" & Trim(TextBox1.Text) & "'and password='" & Trim(TextBox2.Text) & "'"
'我创建一个SQLDataAdapter对象
Dim da As New SqlDataAdapter(sqlstr, connection)
'创建一个DataSet才对象
Dim ds As New DataSet()
'connection.Open()
da.Fill(ds)
' connection.Close()
t = ds.Tables(0)
If ds.Tables(0).Rows.Count = 0 Then 'DataSet1已填充,判断DataSet1数据集中是否有记录,如果没有报错。否则,进入 下一个界面
MsgBox("你输入的用户名或口令有误!", , "提示")
Else
userid = t.Rows(0).Item(0).ToString
user_Pwd = t.Rows(0).Item(1).ToString
userlevel = t.Rows(0).Item(2).ToString
user_s = t.Rows(0).Item(5).ToString
user_a = t.Rows(0).Item(6).ToString
user_e = t.Rows(0).Item(7).ToString
user_d = t.Rows(0).Item(8).ToString
user_p = t.Rows(0).Item(9).ToString
Main.Show()
Me.Hide()
End If
Call DBclose()
End If
End Sub
Private Sub TextBox1_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.GotFocus
TextBox1.BackColor = Color.PaleTurquoise
End Sub
Private Sub TextBox1_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.LostFocus
TextBox1.BackColor = Color.White
End Sub
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress