0

Hello,

I need to start using databases with c++. I know in VB or VBA is simple and easy to find tutorials. I've done a lot of database apps in VBA and VB.
I couldn't find help for c++, only for vc++.
I use Code::Blocks and mingw.
If anyone knows how to start, or have some links, please share.

I want to connect to an Access database. What would be the equivalent in c++ of:

//create connection
Dim myCon as New ADODB.Connection
//create recordset
Dim myRS as New ADODB.Recordset
//create connection string
Dim myConStr as String //"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strFullDBPath & ";"   /how do I set up a driver?

myCon.ConnectionString=myConStr

//create sqlString="SELECT * FROM SomeTable ...."

myCon.Open
myCon.execute sqlString
myRS.Open "" _
    & "SELECT * " _
    & "FROM tblTemp " _
    & "WHERE some_condition " , myCon, adOpenKeyset, adLockOptimistic, -1
Do While Not myRS.EOF
    //some code
    myRS.MoveNext
Loop
Set myRS=Nothing

myCon.Close

I know there are some "sql.h" headers used with "windows.h" but how is a connection declared & initialized?
Please don't tell me to google it because I don't know what to google about.

Thanks!

2
Contributors
4
Replies
23
Views
3 Years
Discussion Span
Last Post by Seba Sama
0

There are millions of examples of how to connect to Microsoft Access database,

ODBC is probably the oldest and most widely used database api in use. Here is a google list of tutorials.

Then there is the Microsoft ADO DLL, I think it's the same as you use in VB. Here are some links for it.

Some database makers also have c and c++ api functions specific to their databases, such as MySQL++ for MySQL database.

If you don't yet know SQL (Structured Query Language) then see some of these tutorials.

Edited by Ancient Dragon

0

Thank you!
BUT:
1. I don't want to use ODBC (setting up the connection in every computer using the app is not a good aproach). Is there a way of setting up an ODBC connection from the code itself?
2. I use Code::Blocks, GNU GCC compiler, and intend to use wxwidgets for the GUI. All those tutorials for ADO are for .NET / Visual C++, and I try not to use MS.
3. SQL I know pretty well, this is not an issue.

Maybe someone can help me with the actual problem I have, which is the use of #import "C:\\Program Files\\Common Files\\System\\ado\\msado28.tlb" that gives me a lot of errors I can't understand (yet):

-------------- Build: Debug in mmmm (compiler: GNU GCC Compiler)---------------

mingw32-g++.exe -Wall -fexceptions -g -std=c++0x  -c "C:\Users\sst5clj\MyFolder\code\cbl\_wxw\_wxSmith tutorials\mmmm\main.cpp" -o obj\Debug\main.o
C:\Users\sst5clj\MyFolder\code\cbl\_wxw\_wxSmith tutorials\mmmm\main.cpp:5:6: warning: #import is a deprecated GCC extension [-Wdeprecated]
In file included from C:\Users\sst5clj\MyFolder\code\cbl\_wxw\_wxSmith tutorials\mmmm\main.cpp:5:0:
C:\\Program Files\\Common Files\\System\\ado\\msado28.tlb:1:1: error: stray '\220' in program
C:\\Program Files\\Common Files\\System\\ado\\msado28.tlb:1:4: warning: null character(s) ignored [enabled by default]
C:\\Program Files\\Common Files\\System\\ado\\msado28.tlb:1:1: error: stray '\3' in program
C:\\Program Files\\Common Files\\System\\ado\\msado28.tlb:1:6: warning: null character(s) ignored [enabled by default]
C:\\Program Files\\Common Files\\System\\ado\\msado28.tlb:1:1: error: stray '\4' in program
C:\\Program Files\\Common Files\\System\\ado\\msado28.tlb:1:10: warning: null character(s) ignored [enabled by default]
C:\\Program Files\\Common Files\\System\\ado\\msado28.tlb:1:1: error: stray '\377' in program
C:\\Program Files\\Common Files\\System\\ado\\msado28.tlb:1:1: error: stray '\377' in program
C:\\Program Files\\Common Files\\System\\ado\\msado28.tlb:1:15: warning: null character(s) ignored [enabled by default]
C:\\Program Files\\Common Files\\System\\ado\\msado28.tlb:1:1: error: stray '\270' in program
C:\\Program Files\\Common Files\\System\\ado\\msado28.tlb:1:18: warning: null character(s) ignored [enabled by default]
C:\\Program Files\\Common Files\\System\\ado\\msado28.tlb:1:1: error: stray '@' in program
C:\\Program Files\\Common Files\\System\\ado\\msado28.tlb:1:26: warning: null character(s) ignored [enabled by default]
C:\\Program Files\\Common Files\\System\\ado\\msado28.tlb:1:1: error: stray '\270' in program
C:\\Program Files\\Common Files\\System\\ado\\msado28.tlb:1:62: warning: null character(s) ignored [enabled by default]
C:\\Program Files\\Common Files\\System\\ado\\msado28.tlb:1:1: error: stray '\16' in program
C:\\Program Files\\Common Files\\System\\ado\\msado28.tlb:1:1: error: stray '\37' in program
C:\\Program Files\\Common Files\\System\\ado\\msado28.tlb:1:1: error: stray '\272' in program
C:\\Program Files\\Common Files\\System\\ado\\msado28.tlb:1:1: error: stray '\16' in program
C:\\Program Files\\Common Files\\System\\ado\\msado28.tlb:1:69: warning: null character(s) ignored [enabled by default]
C:\\Program Files\\Common Files\\System\\ado\\msado28.tlb:1:1: error: stray '\264' in program
C:\\Program Files\\Common Files\\System\\ado\\msado28.tlb:1:1: error: stray '\315' in program
C:\\Program Files\\Common Files\\System\\ado\\msado28.tlb:1:1: error: stray '\270' in program
C:\\Program Files\\Common Files\\System\\ado\\msado28.tlb:1:1: error: stray '\1' in program
C:\\Program Files\\Common Files\\System\\ado\\msado28.tlb:1:1: error: stray '\315' in program
C:\\Program Files\\Common Files\\System\\ado\\msado28.tlb:3:2: warning: null character(s) ignored [enabled by default]
C:\\Program Files\\Common Files\\System\\ado\\msado28.tlb:3:1: error: stray '\1' in program
C:\\Program Files\\Common Files\\System\\ado\\msado28.tlb:3:1: error: stray '\365' in program
C:\\Program Files\\Common Files\\System\\ado\\msado28.tlb:3:1: error: stray '\331' in program
C:\\Program Files\\Common Files\\System\\ado\\msado28.tlb:3:1: error: stray '\24' in program
C:\\Program Files\\Common Files\\System\\ado\\msado28.tlb:3:1: error: stray '\233' in program
C:\\Program Files\\Common Files\\System\\ado\\msado28.tlb:3:1: error: stray '\212' in program
C:\\Program Files\\Common Files\\System\\ado\\msado28.tlb:3:1: error: stray '\24' in program
C:\\Program Files\\Common Files\\System\\ado\\msado28.tlb:3:1: error: stray '\233' in program
C:\\Program Files\\Common Files\\System\\ado\\msado28.tlb:3:1: error: stray '\212' in program
C:\\Program Files\\Common Files\\System\\ado\\msado28.tlb:3:1: error: stray '\24' in program
C:\\Program Files\\Common Files\\System\\ado\\msado28.tlb:3:1: error: stray '\233' in program
C:\\Program Files\\Common Files\\System\\ado\\msado28.tlb:3:1: error: stray '\212' in program
C:\\Program Files\\Common Files\\System\\ado\\msado28.tlb:3:1: error: stray '\17' in program
C:\\Program Files\\Common Files\\System\\ado\\msado28.tlb:3:1: error: stray '\212' in program
C:\\Program Files\\Common Files\\System\\ado\\msado28.tlb:3:1: error: stray '\24' in program
C:\\Program Files\\Common Files\\System\\ado\\msado28.tlb:3:1: error: stray '\233' in program
C:\\Program Files\\Common Files\\System\\ado\\msado28.tlb:3:1: error: stray '\212' in program
C:\\Program Files\\Common Files\\System\\ado\\msado28.tlb:4:1: error: stray '\212' in program
C:\\Program Files\\Common Files\\System\\ado\\msado28.tlb:4:1: error: stray '\24' in program
C:\\Program Files\\Common Files\\System\\ado\\msado28.tlb:4:1: error: stray '\233' in program
C:\\Program Files\\Common Files\\System\\ado\\msado28.tlb:4:1: error: stray '\212' in program
C:\\Program Files\\Common Files\\System\\ado\\msado28.tlb:4:1: error: stray '\24' in program
C:\\Program Files\\Common Files\\System\\ado\\msado28.tlb:4:1: error: stray '\233' in program
C:\\Program Files\\Common Files\\System\\ado\\msado28.tlb:4:1: error: stray '\212' in program
C:\\Program Files\\Common Files\\System\\ado\\msado28.tlb:4:14: warning: null character(s) ignored [enabled by default]
C:\\Program Files\\Common Files\\System\\ado\\msado28.tlb:4:32: warning: null character(s) ignored [enabled by default]
C:\\Program Files\\Common Files\\System\\ado\\msado28.tlb:4:1: error: stray '\206' in program
C:\\Program Files\\Common Files\\System\\ado\\msado28.tlb:4:1: error: stray '\1' in program
C:\\Program Files\\Common Files\\System\\ado\\msado28.tlb:4:37: warning: null character(s) ignored [enabled by default]
C:\\Program Files\\Common Files\\System\\ado\\msado28.tlb:4:1: error: stray '\237' in program
C:\\Program Files\\Common Files\\System\\ado\\msado28.tlb:4:1: error: stray '\336' in program
C:\\Program Files\\Common Files\\System\\ado\\msado28.tlb:4:1: error: stray '\316' in program
C:\\Program Files\\Common Files\\System\\ado\\msado28.tlb:4:42: warning: null character(s) ignored [enabled by default]
C:\\Program Files\\Common Files\\System\\ado\\msado28.tlb:4:1: error: stray '\360' in program
C:\\Program Files\\Common Files\\System\\ado\\msado28.tlb:4:51: warning: null character(s) ignored [enabled by default]
C:\\Program Files\\Common Files\\System\\ado\\msado28.tlb:4:52: warning: null character(s) preserved in literal [enabled by default]
C:\\Program Files\\Common Files\\System\\ado\\msado28.tlb:4:52: warning: missing terminating " character [enabled by default]
C:\\Program Files\\Common Files\\System\\ado\\msado28.tlb:4:1: error: missing terminating " character
In file included from C:\Users\sst5clj\MyFolder\code\cbl\_wxw\_wxSmith tutorials\mmmm\main.cpp:5:0:
C:\\Program Files\\Common Files\\System\\ado\\msado28.tlb:5:1: warning: null character(s) ignored [enabled by default]
C:\\Program Files\\Common Files\\System\\ado\\msado28.tlb:5:3: error: stray '\214' in program
C:\\Program Files\\Common Files\\System\\ado\\msado28.tlb:6:1: warning: null character(s) ignored [enabled by default]
C:\\Program Files\\Common Files\\System\\ado\\msado28.tlb:6:3: error: stray '\360' in program
Process terminated with status 1 (0 minute(s), 30 second(s))
50 error(s), 19 warning(s) (0 minute(s), 30 second(s))

If I could get this to work I think I'll be OK.

Thank you!

0

I missed that, but I remember seeing it somewhere. Maybe I noticed VISUAL and skipped it.
It seems like direct ODBC could be my way.
I'll test a little bit and come back with some feedback :)

Thank you!

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.