.mdb.access数据库VBA-在已有的数据库中创建数据表(ADOX) |
| 时间:2025-01-20 08:51:45 来源: 作者: |
在已有的数据库中创建数据表(ADOX) 引用:microsoft ADO Ext.2.x for ddl and securityGuF检测VBA 代码:GuF检测VBA public sub1_5()GuF检测VBA Dim mycat as new adox.catalog ‘定义ADOX的catalog对象变量GuF检测VBA dim mytbl as new table ‘定义table对象变量GuF检测VBA dim mydata as string ‘定义数据库名称变量GuF检测VBA dim mytable as string ‘定义数据表名称变量GuF检测VBA GuF检测VBA ‘设置数据库名称(包括完整路径)GuF检测VBA mydata=thisworkbook.path & “\学生成绩管理.mdb”GuF检测VBA ‘设置要创建的数据表名称GuF检测VBA mytable=”期末成绩”GuF检测VBA ‘建立与数据库的连接GuF检测VBA mycat.activeconnection=”provider=microsoft.jet.oledb.4.0;”_GuF检测VBA & “data source=” & mydataGuF检测VBA ‘删除数据库中已经存在的数据表GuF检测VBA mycat.table.delete mytableGuF检测VBA ‘创建数据表,并添加字段GuF检测VBA with mytblGuF检测VBA .name=mytableGuF检测VBA .columns.append “学号”, advarwchar,10GuF检测VBA .columns.append “姓名”, advarwchar,6GuF检测VBA .columns.append “性别”, advarwchar,1GuF检测VBA .columns.append “班级”, advarwchar,10GuF检测VBA .columns.append “数学”, adsingleGuF检测VBA .columns.append “语文”, adsingleGuF检测VBA .columns.append “物理”, adsingleGuF检测VBA .columns.append “化学”, adsingleGuF检测VBA .columns.append “英语”, adsingleGuF检测VBA .columns.append “总分”, adsingleGuF检测VBA end withGuF检测VBA ‘将创建的数据表添加到ADOX的tables集合中GuF检测VBA mycat.tables.append mytblGuF检测VBA ‘释放变量GuF检测VBA set mycat=nothingGuF检测VBA set mytbl=nothingGuF检测VBA ‘弹出信息GuF检测VBA msgbox “数据表<” & mytable & “>创建成功!”,vbinformation,”创建数据表”GuF检测VBA end sub
注:Activeconnection属性用来指示catalog所属的ADO Connection对象,表示到数据源的打开的连接。 |
|
|
|