I'm getting quite annoyed by the lack of information about using DAO with C++ on the internetz. Since I have a thing to fix I have to fiddle a bit with it and I'm thinking of jumping out the windows instead :)
The only examples I find are VB6, VB.Net and VBA related. I have tried to apply them to C++ and have the following thing
...
WideString sqlQuery = WideString(
"SELECT * "\
"FROM NODES "\
"WHERE ID = " + IntToStr(NODE_ID));
Dao_2k::RecordsetPtr pNewRecord;
pNewRecord = m_dbDatabase->OpenRecordset(sqlQuery.c_bstr(), OleVariant(RecordsetTypeEnum::dbOpenDynaset));
...
But it just doesn't not want to work. I first tried with just the sql query, then I added the dbOpenDynaset
setting and trying others. But execution just halts. I'm thinking there might be more variables needed to the OpenRecordset
function in C++ but the IDE have no documentation about it so I'm kinda fumbling in the dark.
The select will actually contain a few joins but I stripped it down to see if that was the issue. But both this simple and the more complex query executes within Access.
I got it to work using a bit of the principles described in VB tutorials and some other sources. Something like this should work.
Not though that Access is horrible at handleing SQL syntax. JOINS require a strange set of parentheses and I haven't been able to make it do a UNION yet :)