VB连接ACCESS数据库登陆模块请高手帮忙

来源:百度知道 编辑:UC知道 时间:2024/07/02 07:24:01
我写个登陆窗体:
我用了个模块,代码如:
Option Explicit
Public con As ADODB.Connection '定义数据连接,公共变量
Public coon, coom As String
Sub main()
Set con = New ADODB.Connection
con.ConnectionString = "provider=microsoft.jet.oledb.4.0;Data Source=" & App.Path & "\data\tbook.mdb;Persist Security Info=False"
'定义数据库连接
con.CursorLocation = adUseClient '以客户端的方式打开
con.Open
logo.Show 'logo是登陆窗体名
End Sub

logo登陆窗体登陆按钮代码如下:
Private Sub Command1_Click()
If (Text1.Text = "") Or (Text2.Text = "") Then
MsgBox "用户名和密码不能为空!", vbOKOnly, "错误"
Text1.Text = ""
Text2.Text = ""
Text1.SetFocus
Exit Sub
End If
Dim rs As New ADODB.Recordset
coon = Text1.Text
coom = Text2.Text
SQL = "select * from user where user='" + coon + "' and password='" + coom + "'" &#

我是这样做的
模块
Private conn As New ADODB.Connection
Public Sub OpenConn()
With conn
If .State = adStateClosed Then
.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "/addresslist.mdb;Persist Security Info=False"
.Open
End If
End With
End Sub
Public Function OpenRecordset(ByVal strSql As String) As ADODB.Recordset
Dim rs As New ADODB.Recordset
With rs
.CursorLocation = adUseClient
.CursorType = adOpenDynamic
.Open strSql, conn, , , adCmdText
End With
Set OpenRecordset = rs
End Function
Public Function RunTrans(ByVal tranSql As String)
With conn
.BeginTrans
.Execute tranSql
.CommitTrans
End With
End Function

窗体
Private Sub Form_Load()
OpenConn
End Sub

你的SQL语句