用VB创建Access表格

'用VB创建Access表格:

'如果程序比较复杂,可添加引用:Microsoft Asctivex Data Objects 2.5 LibraryPrivate

 Private Sub Command1_Click()
    On Error Resume Next
    db = "d:\aa.mdb"
    If Dir(db) = "" Then CreateObject("ADOX.Catalog").Create "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & db
    If Dir(db) = "" Or Err <> 0 Then If MsgBox("数据库创建失败!", 48) <> vbYes Then Exit Sub
    Set con = CreateObject("ADODB.Connection")
    Set rs = CreateObject("ADODB.Recordset")
    con.open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & db
    Set rs.ActiveConnection = con
    rs.open "create table aaa (aa char(2),bb date,cc int)"
    rs.open "insert into aaa (aa,bb,cc) values ('aa',#" & Now & "#,11)"
    rs.open "select * from aaa"
    If Not rs.EOF Then
        For i = 0 To rs.fields.Count - 1
            Print "字段名:"; rs.fields(i).Name, "字段值:"; rs.fields(i)
        Next
    End If
    rs.Close
End Sub

 

已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 技术黑板 设计师:CSDN官方博客 返回首页