Link to home
Create AccountLog in
Avatar of butterhook
butterhookFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Simple database connection C++ ODBS DSN datasource

Hi, I would like to connect to a System ODBC data source (DSN) from my C++ application. I am not using MFC. I believe this should be easy but cannot find anything simple anywhere!

I want to run the query 'INSERT INTO TestTable (Field1) VALUES ('Hello World')"

In pseudocode I believe it would be like this

create new database object
open database object from the database 'mydatabase'
run insert query
close database connection
destroy database object

Can anyone help?
ASKER CERTIFIED SOLUTION
Avatar of itsmeandnobodyelse
itsmeandnobodyelse
Flag of Germany image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Avatar of butterhook

ASKER

Thanks, I may need a little time to analyse this.
Avatar of DanRollins
MFC has a CDatabase class to hide all of the complexities of the lower-level SQLXxxxx functions.  The functions are very reliable and since all target computers come with the MFC DLL, there is no particular code bloat or other problems.  Do you have a particular reason to avoide the MFC objects?
There obviously seem to be a lot of ways to do this - I actually used a different method to the both above but I gave you the points  as a gesture of goodwill.
>>>> I actually used a different method to the both above
>>>> but I gave you the points  as a gesture of goodwill.
Thanks ;-)

Can you tell what method you used? You asked for an ODBC access in C++ not using MFC. I know there are some third party libraries and of course you might use COM and ADO. But none of them has any (experienced) advantage over MFC and I would like to agree to Dan regarding the stability and reliabilty of the MFC ODBC implementation.

Regards, Alex