VC通过ADO操作Access2007数据库
(一)查询表是否存在
1. 修改Access2007权限
(1) “开始”标签,右击“所有表”,选择“导航选项”,选中“显示系统对象”,确定
(2) “数据库工具”标签,“用户和权限”,“用户与组权限”,“对象名称”选中“MSysObjects”,选中“读取数据”
2. SQL语句
CAdoConn adoConn;
adoConn.OnInitADOConn();
try
{
_bstr_t sql = "select MSysObjects.Name from MSysObjects where MSysObjects.Name = '***'";
_RecordsetPtr pRecordset;
pRecordset = adoConn.GetRecordSet(sql);
while (adoConn.m_pRecordset->adoEOF == 0)
{
_bstr_t bt = (_bstr_t)m_pRecordset->GetCollect("***"); // 得到表名,此句只是演示
pRecordset->MoveNext();
}
adoConn.ExitConnect();
}
catch(_com_error &e)
{
AfxMessageBox(e.ErrorMessage());
}
(二)创建表
_bstr_t sql = "create table [***] ([Id] counter primary key not null, [Band1] int, [Band2] int, [Band3] int, [Band4] int)";
accessManager.ExecuteSQL(sql);