• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

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

原作者: [db:作者] 来自: [db:来源] 收藏 邀请
连接 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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
[Java] 利用Axis库调用C#的Web Service发布时间:2022-07-10
下一篇:
异步socket的线程分配(C#)发布时间:2022-07-10
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap