SQL ODBC tutorial

Hi there, i'm just wondering if somebody could point me to a good tutorial for this combination with c++,

the sql website tutorials are a hard for me to follow. I've attempted a few different connectors for sql with c++ and ODBC is the only one i could get working, there seems to be loads of tutorials based on how to get connected, but past that point my google searching hasn't turned much up that past that point. For instance, i have my own model which i want to try to connect to, but i can't send querys to that database for some reason. So far I've been able to connect to the default 'mysql' database.

So i'm looking for a step by step tutorial i guess on it all.

Does such a thing exist?
Here just a couple weeks ago I posted a working example for Lamblion here....

http://www.cplusplus.com/forum/windows/51320/


I need to get back to him to see if its working. Just recently he posted and seems to be having some difficulties with casting character pointers.

Basically, the hardest part is connecting. Once you've successfully connected to a database, and have a handle to a database connection, i.e., hConn, then you need to use that to call SQLAllocHandle() to get a handle to a statement, i.e., hStmt. With that you execute valid SQL statements against your database connection. So in other words, you need to know how to write valid SQL too.

The program I gave Lamblion is somewhat complex, and I have it in mind to write a tutorial myself on this, basically starting from the beginning. However, I have to say the only databases I've personally worked with are Microsoft SQL Server, Microsoft Access, and Microsoft Excel. I've never used My Sql.
I'm a complete virgin to server databases, and pretty new to c++, in mysql u have 'models' which i am guessing are databases.

I'm not sure if its the same problem but i had a problem with the 'SQLCHAR' also, i had to change from characters from uni-code to not set which in turn changes 'SQLCHAR' to 'SQLWCHAR' it solved the problem that i was having though. i'll certainly have a look at the code you put in though, if its as complex as you say i'm not too hopeful though.^^

i had to change from characters from uni-code to not set which in turn changes 'SQLCHAR' to 'SQLWCHAR'


I believe you may have got that backwards buggys; Changing from the UNICODE character set to 'not set' should then require the ansi character set as far as I know. I find that 'not set' a bit confusing myself. There really are only two choices as far as I know, and the choices are wide characters or ansi single byte characters (the multi-byte char set is a special case of this latter).

In any case, ODBC should work the same with either character set. I do recommend using the tchar.h macros though.
OK, didn't think it would have any relevance, wasn't sure what the unicode was doing tbh.

When you are using Microsoft Access in the tutorial u have given, is this just been used as a way of viewing the database, or as a 3rd party in the program(not sure if i've said that in the right way), i am wanting to store information into my sql database through a command line (text based game) to start, because i thought they might be the easiest way to implement sql to start.

From what you wrote that is a simple version of code, which honestly is very intimidating still, does SQL come any simpler than that?
I just checked out what I did in that code I posted, and I see I just used chars. It came back to me I translated that code from another example I had that exclusively used the TCHAR macros. The reason I just used char's though is because the TCHAR stuff is so G** D***** ugly! But to compile that code in Visual Studio you absolutely have to set the character set to 'not set' or 'Multi-byte Character Set'.
Topic archived. No new replies allowed.