用VB创建Access表格

前端之家收集整理的这篇文章主要介绍了用VB创建Access表格前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

'用VB创建Access表格:@H_403_3@

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

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
@H_403_3@

@H_403_3@ 原文链接:https://www.f2er.com/vb/260912.html

猜你在找的VB相关文章