Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

Rated
Read 68,933 times

Contents

Related Categories

Using ADO in C++ - Connections & Recordsets

randy

Connections & Recordsets

Let’s begin by creating a connection object.

ADODB::_ConnectionPtr connection;
hr = connection.CreateInstance(__uuidof(ADODB::Connection));

Ok, that was easy. Now let’s create a recordset object.

ADODB::_RecordsetPtr recordset;
hr = recordset.CreateInstance(__uuidof(ADODB::Recordset));

Ok, this looks about as easy as Visual Basic. Somethings wrong. This can’t be that complex C++ stuff. I’m sure it’ll get harder later. Let’s try opening a connection to our database.

connection->CursorLocation = ADODB::adUseClient;
connection->Open(L"Provider=sqloledb;Data Source=fifa;"
    L"Initial Catalog=test;User Id=testsa;Password=testsa;", L"",
    L"", ADODB::adConnectUnspecified);

Easy again. In fact, this all looks like the equivalent Visual Basic code, but using pointers, namespaces and all those C++ thingys. Now let’s create a table using SQL.

recordset->Open("CREATE TABLE mytable (value NVARCHAR(255))",
    connection.GetInterfacePtr(), ADODB::adOpenForwardOnly,
    ADODB::adLockReadOnly, ADODB::adCmdText);

I usually don’t to DDL (Data Definition Language) from ADO, but hell it’s easy.

Randy's article are Copyright 1998-2003 Randy Charles Morin

Comments

  • Posted by souvik on 29 Aug 2005


    yes , it can be used, but in this case , compiler will treat it as auto variable. Compiler will only generate warning.

  • register variable

    Posted by carthyc on 15 Jul 2005

    hai,

    can we use register variable for storing address

  • I now interested in this,hope any news about this:

    Posted by angus on 10 Jul 2005

    :o :(

  • C language and ADO usage

    Posted by rassul on 02 May 2005

    Hi,

    Does anyone know how to use C language (not C++) with ADO and/or ODBC againt SQL Server. Any sample or a link to a sample is very much appreciated. Thanks in advance.

    Rass

  • Adding a Record

    Posted by vohalloran on 24 Apr 2005

    Now show me how to add a new record to the database. After many hours of working on this, I finally got the program to retrieve the records from the Access database, but I have no idea how to add a ...