-
ADO or ODBC?
Hi there.
I have some experience with Win 32 and MFC, but I have never programmed with data base. I have task to write a program which is written in MFC and use access data base, so ask you which i better ADO or ODBC? And which is easier, so I can learn it
fast enought.
Thank you in advance.
-
MFC has a decent enough DAO wrapper.
For Ado you need to either use straight COM or the MFC wrappers for activeX objects.
I'd go with ADO over ODBC as it's better supported and you can do more with it
-
Thank you, but do you know where I can find resources on this topic?
-
-
Thank you. But I finally chose ODBC.
I wrote "odbc c++: in Google, as you told me to do with "ado c++" :))
I learned the basics with the MFC classes for ODBC. But I don't know if I
copy my program to another pc, which files I must give? The .mdb file, the .exe
and .dll-files, Is there something more that I must copy?
Is any registration of the DB required, as I did to make datasource?
-
Depends if the Dll is COM related - if not then you shouldnt need registration.
Some commercial apps I know of that use ODBC distribute the MDAC redistributable file that can be found on MSDN - this should have everything needed for ODBC (as well as OLEDB and ADO).
-
What about datasource, which I made from
Start Menu->Control Panel->Administrative Tools->Data Sources
(ODBC) ? How can I make it on another machine automatically?
-
Not sure...should be part of the ODBC Api...
That's one of the reasons I like ADO...you can load the MSJET (or whatever) driver on the fly without any need for datasources
-
-
I cant find one of my examples of using ADO using C++, so I knocked this together
It works with VC++. You need to pass the FULL PATH of the database (as provided) as a parameter once you have built the exe file
-
>>What about datasource, which I made from
Start Menu->Control Panel->Administrative Tools->Data Sources
(ODBC) ? How can I make it on another machine automatically?
Like so
Code:
CString Attrib;
int iRet=0;
Attrib.Format("%s","DSN=DamageMod;DBQ=C:\\databases\\DatabaseName.mdb;DESCRIPTION=Test;READONLY=FALSE;EXCLUSIVE=FALSE;");
//this adds a SYSTEM DSN for the database to use
iRet=::SQLConfigDataSource(NULL,ODBC_ADD_SYS_DSN,"Microsoft Access Driver (*.mdb)",Attrib);
if(!iRet)
{
iRet=GetLastError();
-
OK. I learned how to use CDatabase and CRecordset.
But I have question. How much of the SQL standart is supported
by this classes. Can I use LEFT/RIGHT JOIN in CRecordset::Open()
and nested queries in CDatabase::ExecuteSQL().
And if this functionality is not supported directly how can I use it?
-
-
I tried today to use one INSERT query like this:
Code:
INSERT INTO Sometable(PersonID,...) VALUES(
(SELECT Id FROM People WHERE Name='some name'),...)
And it says:
Syntax error in INSERT INTO statement.
And I don't know weather or not my error is in the syntax
or the CDatabase don't support nested queries.
-
Here is a good JET SQL reference.
As you can see, you need to lose the VALUES() for a multiple record insert.