Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

ODBC connection in c++

Posted on 2003-11-04
12
Medium Priority
?
544 Views
Last Modified: 2007-12-19
How can make odbc connection and use ADO in c++? Please give me a simple example or point me to the right document.
Any comments is really appreciated.
0
Comment
Question by:prokni
  • 3
  • 3
  • 3
  • +1
10 Comments
 
LVL 9

Expert Comment

by:_ys_
ID: 9681420
Start with the following.

// utilise ado 2.6
#import "msado15.dll" named_guids
// full path is required - shouldn't be too hard to find

This will allow you to access the ADO objects utilising standard COM.
0
 
LVL 9

Expert Comment

by:_ys_
ID: 9681436
BTW, the typical path is

C:\Program Files\Common Files\System\Ado
0
 
LVL 2

Author Comment

by:prokni
ID: 9682329
any sample code? Even simple one t connect t one access db and insert one record in a table?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 9

Expert Comment

by:_ys_
ID: 9685464
Sorry, but I don't even have a C++ compiler installed at the moment.
0
 
LVL 1

Expert Comment

by:jploeg
ID: 9685713
0
 
LVL 3

Expert Comment

by:Madz
ID: 9686476
Do you want to use ODBC or ADO?

For pure ODBC level calls,
Use SQLAllocHandle to get an environment pointer. Then, use SQLSetEnvAttr to set the ODBC version on the environment. Use SQLAllocHandle to allocate the database handle, SQLConnect to create a DB connection.

Then create a STMT handle using SQLAllocHandle. SQLPrepare prepares the STMT handle with whatever query you want to execute. Then, SQLExecute exeutes that query.

You will get the documentation for the APIs in MSDN

Madz
0
 
LVL 2

Author Comment

by:prokni
ID: 9687550
I though ADO uses ODBC connection to make a call. Then maybe it is different in c++. WHat about ADO?
0
 
LVL 3

Accepted Solution

by:
Madz earned 200 total points
ID: 9693364
// You can get the clsid using #import "msado15.dll" named_guids
HRESULT hr = spADOConnection.CoCreateInstance(CLSID_CADOConnection);

hr = spADOConnection->put_Mode(adModeReadWrite);
hr = spADOConnection->put_CommandTimeout(1000);

//Create your connection string
hr = spADOConnection->Open(cbstrConnectionString, NULL, NULL, adConnectUnspecified);

//Set your query in pwszQuery
hr = spADOConnection->Execute(CComBSTR(pwszQuery), &svarRecordsAffected, adCmdText, &spADORecordSet);

Madz
0
 
LVL 3

Expert Comment

by:Madz
ID: 10152702
Well, I certainly do have problems with leaving the question unanswered. prokni has said that he/she cannot test the answer suggested. So, I would expect that he/she would post the problems that were encountered while testing the suggested solution. Without any intimations from both sides, how can one expect the appropriate solution to be arrived at?

I agree that simply accepting the answer would prove wrong in that it would be misleading in the future for others. But, I am suprised that the need to arrive at the solution is driven by the needs of the enterprise and not by personal will. I strongly object to the point that the question is now invalid because the requirements at the questioner's end have changed. Rest is up to the moderator.

Madz
0
 
LVL 2

Author Comment

by:prokni
ID: 10156540
Madz
I am not agree with this part of your comment
>>But, I am suprised that the need to arrive at the solution is driven by the needs of the enterprise and not by personal will.
This is the reality in our life. Personal will does not matter at all!!
I agree with the rest.

I am open for any suggestion from moderator. I am willing to give the complete points to Madz in anyway that is possible without misleading others.

Thanks
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

876 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question