🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Builder 4 and SQL Server

#2406
From: Viatcheslav V. Vassiliev
Date: Thu, 17 Jul 2003 10:42
101 lines
4349 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 (MS Access)
and Interbase (through OLEDB) databases.

"Jig" <markr@jigsaw.com.au> �������/�������� � �������� ���������:
news:3f163783@newsgroups.borland.com...
>
> Thanks for the reply but I am a beginnner. How do I connect to the
database
> to execute my needed queries?
>
> "Viatcheslav V. Vassiliev" <support@oledbdirect.com> wrote in message
> news:3f16351d@newsgroups.borland.com...
> > Of course. You may use BDE if you need TDataSet descendant, you may use
> > ADO/OLEDB/ODBC directly if you do not need UI. Just connect to database
> and
> > execute needed queries.
> >
> > ----------------------------------------------------------------
> > Regards,
> > Viatcheslav V. Vassiliev
> > http://www.oledbdirect.com
> > The fastest way to access MS SQL Server, MS Jet (MS Access)
> > and Interbase (through OLEDB) databases.
> >
> > "Jig" <markr@jigsaw.com.au> �������/�������� � �������� ���������:
> > news:3f161be7@newsgroups.borland.com...
> > > Hi,
> > > I am using C++ Builder 4 and SQL Server, I would like to be able to
> create
> > > applications that will access and manipulate tables within a database
on
> > the
> > > Server. Is this possible with Builder 4?
> > >
> > > Thanks.
> > >
> > >
> >
> >
>
>
Technical Details
Message-ID: <3f1699da@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-01!sn-xit-06!sn-xit-08!supernews.com!news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed.news2me.com!small1.nntp.aus1.giganews.com!border1.nntp.aus1.giganews.com!nntp.giganews.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <3f161be7@newsgroups.borland.com> <3f16351d@newsgroups.borland.com> <3f163783@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII
X-Google-Thread: 10698b,bf4485774dfe19
X-Google-Attributes: gid10698b,public
X-Google-ArrivalTime: 2003-07-17 06:00:15 PST
From: "Viatcheslav V. Vassiliev" <support@oledbdirect.com>
Newsgroups: borland.public.cppbuilder.database.ado
References: <3f161be7@newsgroups.borland.com> <3f16351d@newsgroups.borland.com> <3f163783@newsgroups.borland.com>
Subject: Re: Builder 4 and SQL Server
Date: Thu, 17 Jul 2003 14:42:17 +0400
Lines: 103
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
NNTP-Posting-Host: 213.247.201.57
Message-ID: <3f1699da@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1058445786 213.247.201.57 (17 Jul 2003 05:43:06 -0700)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-01!sn-xit-06!sn-xit-08!supernews.com!news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed.news2me.com!small1.nntp.aus1.giganews.com!border1.nntp.aus1.giganews.com!nntp.giganews.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail