读书人

vb+SQL登陆代码有关问题

发布时间: 2012-01-31 21:28:41 作者: rapoo

vb+SQL登陆代码问题
刚刚高手帮我解决了连接问题,突然发现还有其他地方有问题.代码:
Private Sub Command1_Click()
Dim student As String
Dim i As Integer
Dim n As Integer
Dim cn As New ADODB.Connection
Set cn = New ADODB.Connection
cn.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=student;Data Source=6C6CF07F486A42C "
cn.Open
If Text1.Text = " " Then
MsgBox "请输入学号! ", vbOKOnly + vbInformation, "用户登陆 "
Text1.SetFocus
Exit Sub
Else
GetConnected
Set rs = New ADODB.Recordset
student = "select * from s where sname= ' " & Text1.Text & " ' "
rs.Open student, cn, adOpenDynamic, adLockOptimistic
If rs.EOF = True And rs.BOF = True Then
Text1.Text = " "
Text2.Text = " "
MsgBox "没有这个用户,请重新输入! ", vbOKOnly + vbExclamation, "警告 "
Text1.SetFocus
Else
If Text1.Text = rs!sname Then
Text2.Text = rs!sno
rs.Close


Me.Hide
Form3.Show
Unload Me
Else
n = n + 1
If n < 3 Then
i = MsgBox( "用户名或密码错误,请重新输入! ", vbCritical + vbRetryCancel + vbDefaultButton1, "登录失败 ")
If i = vbRetry Then
Text1.Text = " "
Text2.Text = " "
Text1.SetFocus
Else
End
End If
Else
MsgBox "三次错误,请退出! ", vbOKOnly + vbExclamation, "登录失败 "
End
End If
End If
End If
End If
End Sub

突然发现没有验证密码的.我刚学不知道在什么地方加什么东西可以.
SQL 2000,VB 6.0
student数据库 表s (sname,sno) sname是帐号Text1 sno做密码Text2.学生登陆系统.
还就是输错3次密码自动关闭也用不了.

[解决办法]
……
……
If rs.EOF = True And rs.BOF = True Then
Text1.Text = " "
Text2.Text = " "
MsgBox "没有这个用户,请重新输入! ", vbOKOnly + vbExclamation, "警告 "
Text1.SetFocus
n=n+1
if n> =3 then goto g_out
Else
===========在这一部分添中验证密码的代码
If Text1.Text = rs!sname Then
Text2.Text = rs!sno
rs.Close
Me.Hide
Form3.Show
Unload Me
Else
n = n + 1
If n < 3 Then
i = MsgBox( "用户名或密码错误,请重新输入! ", vbCritical + vbRetryCancel + vbDefaultButton1, "登录失败 ")


If i = vbRetry Then
Text1.Text = " "
Text2.Text = " "
Text1.SetFocus
Else
End
End If
Else
g_out: MsgBox "三次错误,请退出! ", vbOKOnly + vbExclamation, "登录失败 "
End
End If
End If
End If
End If
End Sub

还有你必须把n声明为公共变量才可以

读书人网 >VB

热点推荐