VB2010+ACCESS做登陆窗体
那位大侠有VB2010+ACCESS做的登陆窗体代码啊,小弟感激不尽
小弟刚刚开始学习VB,希望各位多多帮助
Private Sub login()
If TextBox1.Text = "" Then
MsgBox("用户名不能为空!请输入用户名。")
TextBox1.Focus()
Else
Dim cnn As New OleDbConnection
cnn.ConnectionString = "Provider=Microsoft.ace.OLEDB.12.0;Data Source=………\data\11.accdb "
cnn.Open()
Dim ds As New DataSet
Dim da As New OleDbDataAdapter("select * from [user]", cnn)
cnn.Close()
da.Fill(ds, "user")
If ds.Tables(0).Rows.Count <> 0 Then
Dim sql As String = "select * from [user] where username='" & Trim(TextBox1.Text) & "' "
Dim da1 As New OleDbDataAdapter(sql, cnn)
Dim ds1 As New DataSet
da1.Fill(ds1, "user")
If ds1.Tables(0).Rows.Count = 0 Then
MsgBox("用户名错误!")
TextBox1.Text = ""
TextBox1.Focus()
Else
If TextBox2.Text = "" Then
MsgBox("请输入密码!")
TextBox2.Focus()
Else
Dim sq2 As String = "select * from [user] where username='" & Trim(TextBox1.Text) & "' and password ='" & Trim(TextBox2.Text) & "'"
Dim da2 As New OleDbDataAdapter(sql, cnn)
Dim ds2 As New DataSet
da2.Fill(ds2, "user")
If ds2.Tables(0).Rows.Count = 0 Then
MsgBox("密码错误!请重新输入密码!")
TextBox2.Text = ""
TextBox2.Focus()
Else
Me.Hide()
main.Show()
End If
End If
End If
End If
End If
在button上建立事件
[解决办法]
Dim sq2 As String = "select * from [user] where username='" & Trim(TextBox1.Text) & "' and password ='" & Trim(TextBox2.Text) & "'"
Dim da2 As New OleDbDataAdapter(sql, cnn)
这里要修改下
改为
Dim sq2 As String = "select password from [user] where username='" & Trim(TextBox1.Text) & "'and password ='" & Trim(TextBox2.Text) & "'"
Dim da2 As New OleDbDataAdapter(sq2, cnn)