读书人

难有关问题希望高手解决!

发布时间: 2012-01-14 20:02:35 作者: rapoo

难问题希望高手解决!!!~~~~
Option Explicit
Public conn As ADODB.Connection '数据库连接
Public Function getdbconnstring() As String
Dim getdbconn As String
getdbconn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & App.Path & "\MingKe.mdb;Persist Security Info=False "
Dim conn As New ADODB.Connection
conn.CursorLocation = adUseClient
conn.Open getdbconn
End Function 公共模块中的程序

'frmlogin 中的程序
Private Sub cmdOK_Click()


Call getdbconnstring

Dim rs As New ADODB.Recordset
rs.Open "select * from sysUser ", conn, adOpenStatic, adLockBatchOptimistic
If txtUsername.Text = " " Then
MsgBox "用户名不能为空! ", vbOKOnly + vbExclamation
txtUsername.SetFocus
Exit Sub
End If

If txtUserpw.Text = " " Then
MsgBox "密码不能为空! ", vbOKOnly + vbExclamation
txtUserpw.SetFocus
Exit Sub
End If

rs.MoveFirst
Do While Not rs.EOF
If rs!UserName = txtUsername.Text Then

If rs!userpw = txtUserpw.Text Then
Unload Me
Load MDIMain
MDIMain.Show
Exit Sub
Else
MsgBox "密码不正确,请重输! ", vbOKOnly + vbExclamation
txtUserpw.SetFocus
Exit Sub

End If
End If
rs.MoveNext
If rs.EOF Then
MsgBox "此用户不存在! ", vbOKOnly + vbExclamation
txtUsername.SetFocus
Exit Sub
End If
Loop

End Sub



[解决办法]
将 getdbconnstring 写入 sub main() 中

读书人网 >VB

热点推荐