vb怎么链接数据库 教会我追加200分

来源:百度知道 编辑:UC知道 时间:2024/06/06 19:23:10
随便搞了一个登陆界面
要怎么链接数据库啊
我用的server

模块
Public Sub Main()
Form1.Show
End Sub
Public Function Conn() As String
Conn = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" & IIf(Right(App.Path, 1) = "\", App.Path, App.Path & "\") & "Data.mdb;"
End Function
Public Function SQL(ByVal S As String) As ADODB.Recordset
On Error GoTo SQL_Error
Dim Db As New ADODB.Connection
Db.CursorLocation = adUseClient
Db.Open Conn
If InStr("INSERT,DELETE,UPDATE,EXECUTE,ALTER,TRUNCATE", UCase(S)) Then
Db.Execute (S)
Else
Dim Rs As New ADODB.Recordset
Rs.Open Trim(S), Db, adOpenStatic, adLockOptimistic
Set SQL = Rs
End If
SQL_Exit:
Set Rs = Nothing
Set Db = Nothing
Exit Function
SQL_Error:
MsgBox "错误代码" & Err.Number & ",错误描叙: " & Err.Description, vbExclamation, "数据库操作错误