Dim str As String
Dim conn As Connection
Dim rs As RecordsetPrivate Sub cmd_Click() If rs.State = 1 Then rs.Close
sql = "select * from nt_user where usercode='" & Trim(usercode.Text) & "' and userpasswd='" & Trim(password.Text) & "'"
rs.Open sql, conn, adOpenKeyset, adLockOptimistic
If rs.RecordCount > 0 Then
mdimain.Show
Unload main
Else
If MsgBox("请输入有效的用户名和密码", vbInformation, "错误") = vbOK Then
End If
End If
End SubPrivate Sub cmdcancle_Click()
Unload Me
End SubPrivate Sub Form_Load()
Set conn = New ADODB.Connection
str = "Data Source=NTMIT;User ID=sa;Password=ntmitkoei;Initial Catalog=ntsql"
conn.Provider = "SQLOLEDB"
conn.ConnectionString = str
conn.Open
sql = "Select * from nt_user"
Set rs = New ADODB.Recordset
Set rs.ActiveConnection = conn
rs.CursorLocation = adUseServer
rs.Open sql, conn, adOpenKeyset, adLockOptimisticEnd SubPrivate Sub password_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
cmd_Click
End IfEnd Sub
Private Sub usercode_KeyPress(KeyAscii As Integer)
If rs.State = 1 Then rs.Close
sql = "select * from nt_user where usercode='" & Trim(usercode.Text) & "'"
rs.Open sql, conn, adOpenKeyset, adLockOptimistic
If KeyAscii = 13 Then
username.Text = rs!username
password.SetFocus
End If
End Sub
Dim conn As Connection
Dim rs As RecordsetPrivate Sub cmd_Click() If rs.State = 1 Then rs.Close
sql = "select * from nt_user where usercode='" & Trim(usercode.Text) & "' and userpasswd='" & Trim(password.Text) & "'"
rs.Open sql, conn, adOpenKeyset, adLockOptimistic
If rs.RecordCount > 0 Then
mdimain.Show
Unload main
Else
If MsgBox("请输入有效的用户名和密码", vbInformation, "错误") = vbOK Then
End If
End If
End SubPrivate Sub cmdcancle_Click()
Unload Me
End SubPrivate Sub Form_Load()
Set conn = New ADODB.Connection
str = "Data Source=NTMIT;User ID=sa;Password=ntmitkoei;Initial Catalog=ntsql"
conn.Provider = "SQLOLEDB"
conn.ConnectionString = str
conn.Open
sql = "Select * from nt_user"
Set rs = New ADODB.Recordset
Set rs.ActiveConnection = conn
rs.CursorLocation = adUseServer
rs.Open sql, conn, adOpenKeyset, adLockOptimisticEnd SubPrivate Sub password_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
cmd_Click
End IfEnd Sub
Private Sub usercode_KeyPress(KeyAscii As Integer)
If rs.State = 1 Then rs.Close
sql = "select * from nt_user where usercode='" & Trim(usercode.Text) & "'"
rs.Open sql, conn, adOpenKeyset, adLockOptimistic
If KeyAscii = 13 Then
username.Text = rs!username
password.SetFocus
End If
End Sub
解决方案 »
- Excel vba编程保存的问题
- AXA(BE) 代表的是啥?
- 高手帮忙看下如下代码,怎么能在拖动VScroll1时,mschart的显示能反映更快??
- 如何把系统服务设置成为自动.手动.禁止状态?(高手请帮帮忙)
- C++ To VB
- 请问为什么别人运行我的程序会出现运行时错误,组件未能正确注册?
- 虚拟数据源,贴了代码急急急急急急急急急急!(在线等!)
- 在不知道文件存放路径的情况下怎么读取文件
- {求助}DBGrid记录怎样赋值给另一个窗体的TEXT
- 请问大虾:如何在VB中进行可见即可得的打印预览?
- 谁有 VB鼠标滚轮伴侣 ?
- webbrowser 中 NavigateComplete2 和 NavigateComplete的区别是什么?
If rs.Eof=false Then
你使用的是服务器端游标
使用服务器端游标rs.recordset就是-1
把它改成
rs.Open sql,cnns,adOpenForwardOnly ,adLockReadOnly
就好了!!