C++ and ADO (ActiveX Data Objects)
Hello,
I need to write a simple C++ program that:
1) creates a table in an existing database
2) inserts a record in the table and
3) reads a record from the table
Can someone provide me with a simple code (or suggest to me an online tutorial) for doing the above tasks using ADO (ActiveX Data Object)?
I searched on the internet but I couldn't find a simple sample code addressing the above issues.
My C++ program needs to access an SQL Server 2005 Database.
Many thanks in advance.
Re: C++ and ADO (ActiveX Data Objects)
The Google search for ado vc++ example displays the first item to be ADO Code Examples in Visual C++. Now you can open any of the links to see how to begin working with ADO.
To connect to the SQL Server 2005 Database - use one of the related connection strings.
To create a table - use CREATE TABLE ... T_SQL clause, to insert a record - INSERT INTO ..., to read a record(s) - SELECT ... FROM ....
Re: C++ and ADO (ActiveX Data Objects)
Code:
class CClientPlanRS : public CADORecordBinding, public CADORecordset
{
BEGIN_ADO_BINDING(CClientPlanRS)
ADO_FIXED_LENGTH_ENTRY ( 1,
adInteger, m_lClient_Key, m_ulClient_KeyStatus, TRUE)
ADO_VARIABLE_LENGTH_ENTRY2( 2,
adVarWChar, m_szClient_Name, sizeof(m_szClient_Name),
m_ulClient_NameStatus, TRUE)
ADO_VARIABLE_LENGTH_ENTRY2( 3,
adVarWChar, m_szClient_Description,
sizeof(m_szClient_Description),
m_ulClient_DescriptionStatus, TRUE)
END_ADO_BINDING()
//Attributes
public:
LONG m_lClient_Key;
ULONG m_ulClient_KeyStatus;
CHAR m_szClient_Name[51];
ULONG m_ulClient_NameStatus;
CHAR m_szClient_Description[256];
ULONG m_ulClient_DescriptionStatus;
CClientPlanRS(CADODatabase* pDb, int nCacheSize = -1) :
CADORecordBinding(),
CADORecordset(pDb, nCacheSize)
{ SetRecordBinding(this); }
};
however my recommendation would be to use ADO.NET under managed C++ or C# much easier
you can use native SQL driver for .net or OLE.DB , ODBC
Re: C++ and ADO (ActiveX Data Objects)
Quote:
Originally Posted by
aamir121a
Code:
class CClientPlanRS : public CADORecordBinding, public CADORecordset
{
...
};
Interesting!
But how to create a Table using these classes?
And what is CADORecordset class?
Re: C++ and ADO (ActiveX Data Objects)
Thanks for your replies, but I do not even know the very basics of ADO programming in C++, so they did not help me...
Re: C++ and ADO (ActiveX Data Objects)
Quote:
Originally Posted by
nikolasapl
Thanks for your replies, but I do not even know the very basics of ADO programming in C++, so they did not help me...
Well, I didn't know anything about ADO about 10 years ago either!
But reading MSDN documentation + testing some of MSDN examples + searching in the Web about ADO helped me to understand it a little and then use it in my Apps.
In addition to previous links:
ADO is AOK (a simple ADO tutorial)
ADO is AOK - Part II
Re: C++ and ADO (ActiveX Data Objects)
MSDN is really helpful
Many thanks!