C# Access2003/2007 连接字符串总结

连接 Access 2007 的操作方法
//无密码的连接字符串
stringconStr = "Provider=Microsoft.Ace.OleDb.12.0;";
conStr += @"Data Source=E:\数据库\XiaoZhen.accdb;";
conStr += "Persist Security Info=False;";

//有密码的连接字符串
stringconStr = "Provider=Microsoft.Ace.OleDb.12.0;";
conStr += @"Data Source=E:\数据库\XiaoZhen.accdb;";
conStr += "Jet OleDb:DataBase Password='829321';";

连接 Access 2003的操作方法

//无密码的连接字符串
stringconStr = "Provider=Microsoft.Jet.OleDb.4.0;";
conStr += @"Data Source=E:\数据库\XiaoZhen.mdb;";
conStr += "Persist Security Info=False;";

//有密码的连接字符串
stringconStr = "Provider=Microsoft.Jet.OleDb.4.0;";
conStr += @"Data Source=E:\数据库\XiaoZhen.mdb;";
conStr += "Jet OleDb:DataBase Password='829321';";

<connectionStrings>
<add name="ConnectionString" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;
Data Source=F:\TeacherSystem\App_Data\db.mdb;
Jet OLEDB:Database Password=123"providerName="System.Data.OleDb"/>
</connectionStrings>

 

Private Sub CommandButton2_Click()
    Dim myCon      As New ADODB.Connection
    Dim myRst      As New ADODB.Recordset
    Dim myFileName As String
    Dim myTblName  As String
    Dim myKey      As String
    Dim dbFile As String
    Dim mySht      As Worksheet
    Dim i          As Long
    Dim j          As Long
    Dim sql As String
    sql = Space$(10000)
    Dim sql2 As String
    sql2 = Space$(10000)
    Dim sql3 As String
    sql3 = Space$(10000)
    
    TbName = Cells(1, 8)
    myFileName = "db1.mdb"
    dbFile = "C:\Program Files\SWTOOLS\TXT\" & myFileName & ";"
    myCon.Open "Provider=MSDASQL;Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=" & dbFile
    
        '创建表
        sql = "CREATE TABLE [" & TbName & "]("
        For i = 2 To 255
            ZdName = Cells(2, i)
            ZdType = Cells(3, i)
            If i = 2 And ZdType = "int" Then ZdType = "AUTOINCREMENT"
            ZdNull = Cells(5, i)
            If ZdName = "" Then Exit For
            If ZdNull = "Y" Then ZdNull = "NULL" Else ZdNull = "NOT NULL"
            sql2 = " " & ZdName & "  " & ZdType & "  " & ZdNull & ","
            sql = sql & sql2
        Next
        sql = sql & "PRIMARY KEY ([ID]));"
        
        'MsgBox Len(sql)
        myCon.Execute sql
        '创建记录
        For j = 6 To 40000
            sql = ""
            Rows(j).Select
            If Cells(j, 2) = "" Then Exit For
            sql = sql & "insert into " & TbName & " values" & Chr(13)
            sql = sql & "('"
            For i = 2 To 255
                ZdName = Cells(2, i)
                ZdCont = Cells(j, i)
                If ZdName = "" Then Exit For
                If i = 2 Then
                    sql = sql & ZdCont
                Else
                    sql = sql & "','" & ZdCont
                End If
            Next
            sql = sql & "');" & Chr(13)
            myCon.Execute sql
        Next
    Set myCon = Nothing
End Sub

Win7x64bit下访问access mdb文件

myCon.Open "Provider=MSDASQL;Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=" & dbFile

转载于:https://www.cnblogs.com/swtool/p/4045680.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值