Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 896
  • Last Modified:

ADODB Connection

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
perci
Asked:
perci
1 Solution
 
perciAuthor Commented:
help
0
 
FrenchFriesCommented:
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
 
publicvoidCommented:
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

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.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now