🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Using ADO with BCB4

#2214
From: Chip Ling
Date: Thu, 16 Oct 2003 14:14
114 lines
4514 bytes
I did another test run here by merging the two lines into one (try to avoid
using the unknown data type FieldPtr)

origin code:
    FieldPtr p = rs->Fields->get_Item(TVariant("Title"));
    String s = p->get_Value();

new code:
    String s = rs->Fields->get_Item(TVariant("Title"))->get_Value();

But this time I got another compile error message as below
[C++ Error] ADOTEST.cpp(54): E2316 'Fields' is not a member of '_Recordset'.

Any help?

Rgds,
Chip Ling

Chip Ling wrote:

> Dear all,
>
> I'm a BCB4 user, I currently found an article on the web saying I can
> connect to any ADO DB by using BCB4.
> Here is the URL
> http://www.rpiconsultants.com/software/Articles/ADOBCB4/ADOBCB4.asp
>
> So I do it a try. But got stuck on one of the code with a user defined
> data type called FieldPtr. Anyone can help?
>
> Here is what I did:
> 1. Import Type Library "Microsoft ActiveX Data Objects 2.0 Library
> (Version 2.0)" to folder c:\Program Files\Borland\CBuilder4\Imports as
> ADODB_TLB.cpp.
>
> 2. Include Unit Hdr ADODB_TLB.h to the main form.
>         #include <vcl.h>
>         #pragma hdrstop
>         #include "ADOTEST.h"                     //my main form cpp
>         #include "ADODB_TLB.h"               //new include header
>
> 3. Place an edit box called txtPubId to the main form.
>
> 4. Place a command button called cmdAdoQuery to the main form.
>
> 5. Place a list box called lstTitles to the main form.
>
> 6. Go to control panel ODBC and set up the System DSN = AccessTestDB and
> point to the Biblio.mdb
>
> 7. At the cmdAdoQuery button click event enter the following code.
>
> void __fastcall TForm1::btnADOQueryClick(TObject *Sender)
> {
>   //Create the connection object
>   TCOM_Connection cn = CoConnection::Create();
>
>   //Use the ODBC DSN 'AccessTestDB' Access Database Biblio.mdb
>   cn->ConnectionString = WideString("DSN=AccessTestDB").Detach();
>   cn->CursorLocation = Adodb_tlb::adUseClient;
>   cn->ConnectionTimeout = 7;
>
>   //Pass 0 in all value to not change the connection string
>   cn->Open(0,0,0,0);
>
>   //Prepare the SQL statement
>   WideString sql = "SELECT Title FROM Titles ";
>   sql += "WHERE PubId = " + txtPubId->Text.Trim();
>
>   lstTitles->Items->Clear();
>
>   //Create the recordset
>   TCOM_Recordset rs = CoRecordset::Create();
>
>   rs->Open(sql.Detach(), (IDispatch *) cn, Adodb_tlb::adOpenDynamic,
>            Adodb_tlb::adLockOptimistic, 0);
>
>   //Check for empty result set
>   if (rs->BOF == true && rs->EOF == true)
>   {
>     MessageBox(NULL, "No records found matching your criteria",
>                "Query", MB_ICONSTOP);
>   }
>   else
>   {
>     // Reference a field object to the Title Field
>     FieldPtr p = rs->Fields->get_Item(TVariant("Title"));     // this
> line gives me error message when compile
>     // Get the field value (Title name)
>     String s = p->get_Value();
>     this->lstTitles->Items->Add(s);
>   }
>
>   //Close the recordset
>   rs->Close();
>
>   //Close the connection
>   cn->Close();
> }
>
> // end of code
>
> I got a compilation error saying that [C++ Error] ADOTEST.cpp(53): E2451
> Undefined symbol 'FieldPtr'.
>
> I do a test by comment out the whole else block and then compile and
> run. Then enter a impossible number on the txtPubID, and I get a not
> found message box. Looks like the whole thing is working except I must
> have missing some of the include file.
>
> Any Help?
>
> Rgds,
> Chip Ling
Technical Details
Message-ID: <3F8EA7AA.BE029408@yahoo.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-08!supernews.com!easynet-quince!easynet.net!news.tele.dk!news.tele.dk!small.news.tele.dk!eusc.inter.net!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <3F8DBB08.3C297236@yahoo.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10698b,60d8269e6d9da7f9
X-Google-Attributes: gid10698b,public
X-Google-ArrivalTime: 2003-10-16 07:40:12 PST
Message-ID: <3F8EA7AA.BE029408@yahoo.com>
Date: Thu, 16 Oct 2003 10:14:02 -0400
From: Chip Ling <chip_ling_vb@yahoo.com>
X-Mailer: Mozilla 4.72 [en] (WinNT; U)
X-Accept-Language: en
MIME-Version: 1.0
Newsgroups: borland.public.cppbuilder.database.ado
Subject: Re: Using ADO with BCB4
References: <3F8DBB08.3C297236@yahoo.com>
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 204.101.58.41
X-Trace: newsgroups.borland.com 1066313499 204.101.58.41 (16 Oct 2003 07:11:39 -0700)
Lines: 115
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-08!supernews.com!easynet-quince!easynet.net!news.tele.dk!news.tele.dk!small.news.tele.dk!eusc.inter.net!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail