无法使用 ACE 驱动程序执行 sql 插入到 .mdb 文件中。适用于 .accdb 文件
我正在使用 ACE 数据库驱动程序。我正在使用 ADOX 创建访问数据库,并尝试使用 SQL 命令插入数据。当文件名使用 .mdb 扩展名时,它不起作用,而使用 .accdb 时它可以工作。我正在使用 x64 ace 驱动程序
//create new database
PMString connectString("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=");
connectString += getFileName().c_str();
ADOX::_CatalogPtr pCatalog(__uuidof(ADOX::Catalog));
try{
pCatalog->Create(connectString.c_str());
}catch( _com_error &e){
throw dymexexception("Error creating table");
}
//init connection
HRESULT hr = CoInitialize(NULL);
if (FAILED(hr))
throw dymexexception("Failed to initialize database");
hr = pConnection.CreateInstance(__uuidof(Connection));
if (FAILED(hr))
throw dymexexception("Failed to initialize database");
hr = pConnection->Open(connectString.c_str(),"","",0);
if(FAILED(hr))
throw dymexexception("Failed to initialize database");
,这是插入部分
//build sql insert query and execute it
queryString = "INSERT INTO " + tableName + " VALUES(";
for(int i=0;i<fieldValues.size();i++)
{
if(i>0)
queryString += ",";
queryString += fieldValues[i];
}
queryString += ")";
executeSqlCmd(pCommand,queryString);
这是executeSqlCmd 函数的位置
AdoNS::_RecordsetPtr ResultDatabase::executeSqlCmd(AdoNS::_CommandPtr pCommand, PMString queryString)
{
pCommand->CommandText = (_bstr_t) queryString.c_str();
return pCommand->Execute(NULL,NULL,NULL);
}
有任何反馈吗?
I am using ACE database driver. I am creating access database using ADOX and am trying to insert the data using SQL command. When the filename is using .mdb extension it doesn't works while it works when using .accdb. I am using the x64 ace driver
//create new database
PMString connectString("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=");
connectString += getFileName().c_str();
ADOX::_CatalogPtr pCatalog(__uuidof(ADOX::Catalog));
try{
pCatalog->Create(connectString.c_str());
}catch( _com_error &e){
throw dymexexception("Error creating table");
}
//init connection
HRESULT hr = CoInitialize(NULL);
if (FAILED(hr))
throw dymexexception("Failed to initialize database");
hr = pConnection.CreateInstance(__uuidof(Connection));
if (FAILED(hr))
throw dymexexception("Failed to initialize database");
hr = pConnection->Open(connectString.c_str(),"","",0);
if(FAILED(hr))
throw dymexexception("Failed to initialize database");
and this is the inserting part
//build sql insert query and execute it
queryString = "INSERT INTO " + tableName + " VALUES(";
for(int i=0;i<fieldValues.size();i++)
{
if(i>0)
queryString += ",";
queryString += fieldValues[i];
}
queryString += ")";
executeSqlCmd(pCommand,queryString);
Where this is the executeSqlCmd function
AdoNS::_RecordsetPtr ResultDatabase::executeSqlCmd(AdoNS::_CommandPtr pCommand, PMString queryString)
{
pCommand->CommandText = (_bstr_t) queryString.c_str();
return pCommand->Execute(NULL,NULL,NULL);
}
Any feedback?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论