vb登陆界面与sql连接问题
Dim Con As New ADODB.Connection '建立connection变量,连接数据库Dim Res As New ADODB.Recordset
Dim i As Integer, j As Integer
Private Sub Command1_Click() '确定
If Text1(0).Text = "" Then '用户名
MsgBox "用户名不能为空,请输入用户名", vbOKOnly + vbInformation, "提示!"
Text1(0).SetFocus
Exit Sub
End If
If Text1(1).Text = "" Then '学号
MsgBox "学号不能为空,请输入学号", vbOKOnly + vbInformation, "提示!"
Text1(1).SetFocus
Exit Sub
End If
For i = 1 To Res.Fields.Count - 1 '判断text值是否与数据库的字段值相等,感觉这一段怪怪的,修改了很多次都不行
If (Text1(i - 1).Text = Res.Fields(i).Value) Then
Unload Form1 '相等就加载页面
Form2.Show
Else
MsgBox ("不存在此记录!") '否则退出系统
Exit Sub
End If
Next i
CloseConn '关闭打开数据库
End Sub
Private Sub Form_Load()
Con.Open "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=学生登录表;Data Source=20090828-1511"
'服务器名称,根据自己的服务器名称进行修改
Res.Open "select * from 登录表", Con, adOpenKeyset, adLockOptimistic
CloseConn
For i = 0 To Res.Fields.Count - 1
Text1(i).Text = ""
Next i
End Sub
Private Sub CloseConn() '关闭再打开数据库
Res.Close
Res.Open
End Sub
希望高手帮我改一改!