Private Sub Command1_Click()
Dim con As adodb.Connection
Dim rs As adodb.Recordset
Dim sql As String If Trim(Text1.Text = "") Then
MsgBox "没有输入用户姓名,请重新输入!", vbOKOnly + vbExclamation, "警告"
Text1.SetFocus
Exit Sub
Else
Set con = New adodb.Connection
con.Open "Provider=sqloledb;Data Source=ice_prince;Initial Catalog=zero;User Id=sa;Password=515712;"
sql = "select * from userinfo where UserID= '" & Trim(Text1.Text) & "' "
Set rs = New adodb.Recordset
rs.Open sql, con, adOpenDynamic, adLockOptimistic (这里出错:不能 比较或排序 text\netxt~~~除非使用is null 或 like 运算)
If rs.EOF And rs.BOF Then
MsgBox "没有这个用户,请重新输入!", vbOKOnly + vbExclamation, "警告"
Text1.SetFocus
rs.Close
Set rs = Nothing
con.Close
Set cn = Nothing
Exit Sub
Else
rs.Close
Set rs = Nothing
con.Close
Set cn = Nothing
MsgBox "登陆成功~", vbInformation
'....登陆成功后的其他操作
End If
End If
End Sub注以上程序代码是 小马哥 所作本人只是借用!!!! rs.Open sql, con, adOpenDynamic, adLockOptimistic (这里出错:不能 比较或排序 text\netxt~~~除非使用is null 或 like 运算)
Private Sub Command1_Click()
Dim con As adodb.Connection
Dim rs As adodb.Recordset
Dim sql As String If Trim(Text1.Text) = "" Then
MsgBox "没有输入用户姓名,请重新输入!", vbOKOnly + vbExclamation, "警告"
Text1.SetFocus
Exit Sub
Else
Set con = New adodb.Connection
con.Open "Provider=sqloledb;Data Source=ice_prince;Initial Catalog=zero;User Id=sa;Password=515712;"
sql = "select * from userinfo where UserID= '" & Trim(Text1.Text) & "'"
Set rs = New adodb.Recordset
rs.Open sql, con
If rs.EOF And rs.BOF Then
MsgBox "没有这个用户,请重新输入!", vbOKOnly + vbExclamation, "警告"
Text1.SetFocus
rs.Close
Set rs = Nothing
con.Close
Set con = Nothing
Exit Sub
Else
rs.Close
Set rs = Nothing
con.Close
Set con = Nothing
MsgBox "登陆成功~", vbInformation
'....登陆成功后的其他操作
End If
End If
End Sub
调试时这句会是什么呢?
Private Sub cmdok_Click()
Dim strsql As String
Dim rs As New ADODB.Recordset
On Error GoTo err
strsql = "select * from password where usr='" & Trim(txtusrname.Text) & "' and pwd='" & Trim(txtpassword.Text) & "'"
rs.Open strsql, g_conn,3,1,1
If rs.EOF Then
MsgBox "用户名或者密码不正确", , "提示"
txtusrname.Text = ""
txtpassword.Text = ""
txtusrname.SetFocus
Else
Unload Me
MDIForm1.Show
End If
Exit Sub
err:
MsgBox "错误", , "警告"
txtusrname.Text = ""
txtpassword.Text = ""
txtusrname.SetFocusEnd Sub
其中g_conn 为数据库连接。我把它做到MODULE里面去了。方面调用。