|
VB怎么连ACCESS?在登录窗口的cmdOK_Click()事件里和在模块里怎么写啊?我现在是按了确定后没反应,下面是模块下的代码
Option Explicit
Public con As New ADODB.Connection
Public Function connecttoserver() As Boolean
On Error GoTo ConnectErr
'连接到数据库
con.CursorLocation = adUseClient
con.ConnectionString = "provider=microsoft.jet.oledb.4.0;""Data sourct=" & App.Path & "\emp.mdb;"
con.ConnectionTimeout = 5 '20秒等待时间
con.Open '打开连接
connecttoserver = True
Exit Function
ConnectErr:
connecttoserver = False
MsgBox "错误代码:" & Err.Number & vbCrLf & _
"错误描述:" & Err.Description, vbCritical + vbOKOnly, "连接错误"
End Function
Public Function ExecuteSQL(ByVal strsql As String) As Boolean
On Error Resume Next
con.Execute (strsql)
If Err.Number <> 0 Then
MsgBox "错误代码:" & Err.Number & vbCrLf & _
"错误描述:" & Err.Description, vbCritical + vbOKOnly, "连接错误"
Err.Clear
ExecuteSQL = False
Else
ExecuteSQL = True
End If
End Function
Public Function DisConnect() As Boolean
On Error Resume Next
If con.State = adStateOpen Then
con.Close
End If
DisConnect = True
End Function
下面是cmdok_click()下的代码
Private Sub cmdOK_Click()
If Text1.Text = "" Or Text2.Text = "" Then
MsgBox "请将登陆信息填写完整!", 16 + vbOKOnly, "登录错误"
Text1.SetFocus
Else
strsql = "select * from managerlist where name='" & Text1.Text & "' and pwd='" & Text2.Text & "'"
End If
请问哪不对啊?或者少了什么语句吗? |
|