connecting with database

how to connect c++ with database ? is ther any tool to connect?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Standard C++ provides no features for this.

However, many operating systems and/or database management systems do provide ways to do this.  So there may be a way to do this for the OS you are running on or the DBMS you need to use, but we woudl need to know these sorts of details.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Are you trying to use ODBC?  If so I have some sample code.
Also, what platform?  Windows, Unix?  What OS?
Become a Certified Penetration Testing Engineer

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

If for windows, I would recommend SQL over ODBC.
"Recommend SQL over ODBC" doesn't make sense. SQL is a data driven query language - it can't be used directly from C++.

What did you mean to say?
He probably want to mean that ODBC to connect to your database uses SQL under the hood.

Raja Nambi,
Are you using MFC? if yes I agree with nietod, ODBC or DAO are easy way to do what you want.
I mean the SQLxxxx() functions.  AFAIK these will use ODBC or other DB interfaces to communicate with the database.  i.e. they are a higher level of abstraction than ODBC.  Of course none of this matters if this is for a Macintosh, Unix, VAX, etc...
Such as SQLExecute()? These are the ODBC API functions.

Or is there another set?
This isn't my area of expertise, but I was under the impression that these functions were a level above ODBC.
Nope - they are ODBC.
Moving back a step, you said you can't access SQL directly with C++?  We have libraries that are SQL only that are used with C++ and not ODBC.  I personally prefer using the ODBC method though, so you can map the ODBC directly to and SQL database table or an Access file (if you would want to do such a thing)
What I meant was: you cannot execute SQL statements in C/C++ code. You have to go through a library that takes the SQL and passes it to the DB engine.

won't do anything - though it will compile.

Perhaps I was being a bit pedantic, but I feel it is best to be explicit when communicating like this.

BTW: ODBC is "SQL only". All data access is done using SQL statments.
For Windows, ActiveX Data Objects (ADO) is the recommended data access technology.
Did you mean to accept my comment as an answer?  It doesn't seem worthy.
raja_nambiAuthor Commented:
actually iam using windows ,for that i want to connect with database,with odbc i couldn't understand how it can be?
You really shouldn't have accepted my comment as the answer, then, because I'm not really the expert on this one.

but to use ODBC (apparently):

(Corrrect me on this stuff if I'm wrong...)

You 1st need to allocate an environment handle wich stores "settings" about how you want to use ODBC.  You do this with  SQLAllocHandle() specifying a handle type of SQL_HANDLE_ENV.  

Then you need to allocat a handle for the database connection, this handle is used to "interact" with a particular database, again you do this with SQLAllochandle() and SQL_HANDLE_DBC and you will need to specify the environment handle you created in the 1st step.  

Then you need to connect to the database, for this use SQLConnect() with the connection handle you created.

Then you can "interact" with the database using the myriad other SQL functions provided.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.