开发者

Cannot execute sql insert into .mdb file using ACE driver. Works with .accdb file

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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜