vb+access

 Attribute VB_Name = "MyMDB"
Option Explicit

'数据库联接
Dim com As ADODB.Command
Dim cn As ADODB.Connection

'程序的路径
Private MDBFile  As String
Private MDBOpen As Boolean

Public Function GetAppPath() As String
    Dim AppPath As String
   
    AppPath = App.Path
    If Right(AppPath, 1) <> "/" Then AppPath = AppPath & "/"
    GetAppPath = AppPath
End Function

'初始化全局变量
Public Function OpenMDB(File As String) As Boolean
    If Dir(File) = "" Then
        MsgBox "数据库文件 '" & File & "' 丢失,程序运行失败!", vbOKOnly, "致命错误!"
        OpenMDB = False
        Exit Function
    End If
   
    '联接数据库
    On Error GoTo error
    Set cn = New ADODB.Connection
    Set com = New ADODB.Command
    cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & File & ";Persist Security Info=False"
    MDBFile = File
    cn.Open  '创建数据库连接
    com.CommandType = adCmdText     '定义ADO命令类型
    com.ActiveConnection = cn
    OpenMDB = True
    Exit Function
error:
    OpenMDB = False
   
End Function

Public Function SQL(strSQL As String) As ADODB.Recordset
    On Error GoTo error
    com.CommandText = strSQL
    Set SQL = com.Execute
    Exit Function
error:
    Set SQL = Nothing
End Function

Public Function SQL2(strSQL As String) As Long
    Dim res As Long
   
    On Error GoTo error
    cn.Execute strSQL, res
    SQL2 = res
    Exit Function
error:
    SQL2 = 0
End Function

Public Function GetCon() As ADODB.Connection
    Set GetCon = cn
End Function

Public Function GetCom() As Command
    Set GetCom = com
End Function

Public Function GetMDBName() As String
    GetMDBName = Mid(MDBFile, InStrRev(MDBFile, "/") + 1)
End Function

http://download.csdn.net/source/349955

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值