?
Solved

ADODB Connection

Posted on 2003-03-31
6
Medium Priority
?
886 Views
Last Modified: 2013-11-20
Hello guys,
Can someone help me how to connect to database using ADO Connection in MFC in the easiest way, where in
using connection string and I can explore the recordset and I Execute SQL Statements


0
Comment
Question by:perci
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 

Author Comment

by:perci
ID: 8242980
help
0
 

Accepted Solution

by:
FrenchFries earned 100 total points
ID: 8245443
The simpliest way to use ADO is to take example on Microsoft samples.

Here are some samples
http://msdn.microsoft.com/library/default.asp?url=/code/list/ado.asp

Have a look also on http://www.codeproject.com


Here is a part of code to read a table :

inline BOOL TESTHR(HRESULT x) {if FAILED(x) _com_issue_error(x);return FALSE;};


_ConnectionPtr p_mConnection;
_variant_t vtValue;
_RecordsetPtr  m_pRecordset;
TESTHR(p_mConnection.CreateInstance(__uuidof(Connection)));
TESTHR(m_pRecordset.CreateInstance(__uuidof(Recordset)));
p_mConnection->Provider = PROVIDER;

try
{
     pConnection->Open(MyConnectionString,"","",NULL);
}
catch(...)

p_mRecordset->Open ("my_table",     _variant_t((IDispatch *)p_mConnection, true),adOpenStatic,adLockReadOnly,adCmdTable);
p_mRecordset->MoveFirst();
vtValue=p_mRecordset->Fields->Item["My_Item"]->Value;
......

p_mRecordset->Close();
p_mConnection->Close();

0
 

Expert Comment

by:publicvoid
ID: 8248395
Check out these classes by  Carlos Antonilli.  They make ADO with MFC so easy!  Use it just like The CDatabase classes but with dynamic binding.  Here is the link:

http://www.codeproject.com/database/caaadoclass1.asp

It took about a 30 mins to learn it.

Good Luck...
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
In this post we will learn different types of Android Layout and some basics of an Android App.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

777 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