🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.database.ado
Article #2144

Re: ADO component on BCB5 pro

#2144
From: Viatcheslav V. Vassiliev
Date: Thu, 23 Oct 2003 10:15
77 lines
3185 bytes
Import ADO type library (choose "Project\Import Type Library" in IDE menu -
choose "Microsoft ActiveX Data Objects 2.x Library"). Add button and memo on
your form

#include <ADODB_TLB.h>

void __fastcall TForm1::Button1Click(TObject *Sender)
{
 ConnectionPtr conn;
 RecordsetPtr rs;

 conn = CoConnection::Create();

 //"Integrated security=SSPI" is for Windows security, you may need "User
ID=myID;Password=password;"
 conn->Open(WideString("Provider=SQLOLEDB;Integrated Security=SSPI;Initial
catalog=pubs;"),
  WideString(""), WideString(""), 0);

 //Open recordset and fetch data
 rs = CoRecordset::Create();
 rs->Open(WideString("Select * from [authors]"), (IDispatch*)conn,
adOpenKeyset, adLockOptimistic, 0);

 rs->MoveFirst();
 while (!(bool)rs->EOF)
 {
  for (int i=0; i<rs->Fields->Count; i++)
  {
   AnsiString str;
   FieldPtr Field;
   Field = rs->Fields->get_Item(i);
   str = WideString(Field->Name) + WideString(" = ");
   str += Field->get_Value();
   Memo1->Lines->Add(str);
  }
  rs->MoveNext();

  Memo1->Lines->Add("");
 }

 rs->Close();
 conn->Close();
}

You can execute DDL commands with conn->Execute method or with CoCommand
object.

For this sample all columns should be convertible to string (otherwise do
not convert Field->getValue() to string). You can use
samples for VC or even for VB with some modifications. Docs are available as
part of MDAC SDK (http://www.microsoft.com/data) or even in "C:\Program
Files\Common Files\SYSTEM\ADO\ADO2XX.CHM" where XX is 10, 50, 60, 70
depending on ADO version. VB examples seems to be closer to BCB syntax than
VC examples.

//----------------------
Regards,
Viatcheslav V. Vassiliev
http://www.oledbdirect.com
The fastest way to access MS SQL Server,
MS Jet (Access) and Interbase (through OLEDB)


"Alain R." <no.valid@email.com> �������/�������� � �������� ���������:
news:3f97a91c$1@newsgroups.borland.com...
> Hi,
>
> I have BCB5 pro only and not entreprise (or BCB6) and I would like to use
> ADO components.
> If i iunderstood right, Microsoft supplied some COM object (ADO) with MDAC
> pilots.
> Could you tell me how to have access to them and how to use them ?
> tia,
> Alain
>
>
Technical Details
Message-ID: <3f97ada1$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!fu-berlin.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <3f97a91c$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII
X-Google-Thread: 10698b,3114124c23836026,start
X-Google-Attributes: gid10698b,public
X-Google-ArrivalTime: 2003-10-23 03:39:29 PST
From: "Viatcheslav V. Vassiliev" <support@oledbdirect.com>
Newsgroups: borland.public.cppbuilder.database.ado
References: <3f97a91c$1@newsgroups.borland.com>
Subject: Re: ADO component on BCB5 pro
Date: Thu, 23 Oct 2003 14:15:15 +0400
Lines: 79
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2600.0000
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
NNTP-Posting-Host: 213.234.218.42
Message-ID: <3f97ada1$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1066904993 213.234.218.42 (23 Oct 2003 03:29:53 -0700)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!fu-berlin.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail