adox创建access数据文件

adox创建access数据文件

    Dim cat As New ADOX.Catalog
    Dim tbl As New ADOX.Table
    Dim pstr As String

    pstr = "Provider=Microsoft.Jet.OLEDB.4.0;"    '不能把这里的4.0改为3.51数据库驱动 4.0 For Office 2k/2003, 3.5.1 For Office 97
    pstr = pstr & "Data Source=" & db
    'pstr = pstr & ";Jet OLEDB:Database Password=" & psw  '如需密码请加上此句

    cat.Create pstr
    cat.ActiveConnection = pstr


    '1''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    tbl.Name = "drugs"
    tbl.Columns.Append "ID", adInteger
    tbl.Columns.Append "Name", adVarWChar, 20
    tbl.Columns.Append "units", adVarWChar, 6
    tbl.Columns.Append "totals", adInteger
    tbl.Columns.Append "date", adDate

    cat.Tables.Append tbl
    Set tbl = Nothing

 

adodc1打开数据库的方法

    Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & db & ";Persist Security Info=False"
    Adodc1.CommandType = adCmdText                  '设置记录源
    Adodc1.RecordSource = "select * from drugs"
    Adodc1.Refresh                                   ' 刷新显示
    Set DataGrid1.DataSource = Adodc1

    Dim rst As New ADODB.Recordset

    Set rst = Adodc1.Recordset
posted @ 2013-05-13 16:49  忘忧般若汤  阅读(352)  评论(0编辑  收藏  举报