【求助】为什么我用vb与数据库的登陆验证只能验证表第一行的数据
vb.net吧
全部回复
仅看楼主
level 1
Private Sub login_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles login_Button.Click
Dim bookCnn As New SqlConnection("Data Source=(local); Initial Catalog=bookSystem;Integrated Security=True")
Dim cmd As New SqlCommand("select * from administrator_Table", bookCnn)
bookCnn.Open()
Dim reader As SqlDataReader = cmd.ExecuteReader
While (reader.Read)
If user_TextBox.Text = Trim(reader("name")) And password_TextBox.Text = Trim(reader("password")) Then
Me.Hide()
welcome.Show()
Else
user_TextBox.Text = Trim(reader("password"))
End If
End While
例如那个表的第一行是 a 密码 123,第二行 b 321 ,我输入 a 123 ,执行了show welcome窗口,但是输入b 321,执行的确是else 那个语句,如何实现 输入 b 321 甚至 c 111 之类的其他行都能够正确执行show呢
我现在第一行的能够正确执行,但是第二行第三行都是执行的是else 那个语句,求好人帮忙,感激不尽!这究竟是为什么?
2012年12月08日 07点12分 1
level 6
当然了,if ……else ……endif,每次循环二者必定要执行一个……
增加一个逻辑变量 初始值为真 加到while条件里(用and连接) 找到了就改变为假 如果循环全部结束了还为真 就提示登录错误 这样一旦符合了 循环就不会继续执行了
2012年12月08日 17点12分 2
谢谢啊!真的很感谢,终于解决了,几天了一直在想这个问题都快疯了~大恩大德无以为报啊~
2012年12月09日 03点12分
1