-
January 30th, 2011, 01:45 AM
#1
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.
Last edited by nikolasapl; January 30th, 2011 at 02:32 AM.
-
January 30th, 2011, 05:15 AM
#2
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 ....
Victor Nijegorodov
-
January 30th, 2011, 07:51 AM
#3
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
-
January 30th, 2011, 08:08 AM
#4
Re: C++ and ADO (ActiveX Data Objects)
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?
Victor Nijegorodov
-
January 30th, 2011, 11:50 AM
#5
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...
-
January 30th, 2011, 12:01 PM
#6
Re: C++ and ADO (ActiveX Data Objects)
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
Victor Nijegorodov
-
January 31st, 2011, 01:04 PM
#7
Re: C++ and ADO (ActiveX Data Objects)
MSDN is really helpful
Many thanks!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|