1 VB编辑器菜单工具-〉引用,把ActiveX Data Objects 2.8选上,然后确定
2 编写连接代码
'指定数据库文件路径返回一个数据库连接对象Connection
Function GetConnection(DBPath As String) As Connection Dim conn As New Connection With conn .Provider = "Microsoft.Jet.OLEDB.4.0" .ConnectionString = DBPath .Open End With Set GetConnection = conn End Function
sub test()
dim conn as Connection
dim rs as RecordSet
dim SqlCmd as new Command
Set conn = GetConnection("F:\CAD\CadDataBase\CadDataBase.mdb") With SqlCmd .ActiveConnection = conn .CommandType = adCmdStoredProc '命令类型为存储过程,adCmdText是普通SQL语句 .CommandText = "Validate" '指出在ACCESS中建立的查询的名称 End With
rs = SqlCmd.Execute , Array(id,pwd) '给定查询所需要的参数 msgbox rs.Feilds("userName").value
rs.close
conn.close
end sub |