🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Problems with & in commandtext select quiery

#2048
From: Matthew Cooper
Date: Thu, 20 Nov 2003 12:24
80 lines
3682 bytes
Hi,

I am using Borland C++ Builder 6 and trying to create a database app using
the ADO components, and have run into a little difficulty. I am also quite
new at using the software.

Basically I want a user to input some text into a text box, and as they do
so the software adjusts its search, changing the results shown. This
basically works, if you type for example 'at' it'll show records starting
with at, but when you type in at& it doesn't display anything. I have worked
out it is the & that is causing the problem, but unsure on how to solve it.

I have tried replacing & with the following:

\&
&&
char(38)

The code from my button:

void __fastcall TForm1::SearchCompanyTextKeyUp(TObject *Sender, WORD &Key,
      TShiftState Shift)
{
        SearchNameText->Text = "";
        ClientDataSet->Active = false;
        CompanyDataSet->Active = false;
        Variant vString(SearchCompanyText->Text.Trim());
        vString = AnsiReplaceText(vString,"'", "''");
        vString = AnsiReplaceText(vString,"&", char(38));
        CompanyDataSet->CommandText = "SELECT * FROM Customer_Company WHERE
(company_name LIKE '" + SearchCompanyText->Text + "%')";
        Label12->Caption = CompanyDataSet->CommandText;
        CompanyDataSet->Active = true;
        if ( CompanyIDDBEdit->Text == "" )
        {
                CompanyDataSet->Active = false;
                CompanyDataSet->CommandText = "SELECT * FROM
Customer_Company";
        }
        else
        {
                ClientDataSet->CommandText = "SELECT * FROM Customer_Client
WHERE (client_company_id = " + CompanyIDDBEdit->Text + ") ORDER BY
client_surname";
                CompanyDataSet->Active = false;
        }
        if ( SearchCompanyText->Text == "" )
        {
                ClientDataSet->CommandText = "SELECT * FROM Customer_Client
ORDER BY client_surname ASC";
                CompanyDataSet->CommandText = "SELECT * FROM
Customer_Company";
        }
        ClientDataSet->Active = true;
        if ( ClientDataSet->Active )
        {
                CompanyDataSet->Active = true;
                Variant statusString(String("Client: "));
                statusString = statusString +
IntToStr(ClientDataSet->RecordCount);
                StatusBar1->SimpleText = statusString;
        }
}

Any help would be greatly appreciated, if you require any more details/info
please ask and I'll try to answer.

Regards

Matthew




---
Outgoing mail is certified Virus Free.

AVG Virus Scanner FREE Edition.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.536 / Virus Database: 331 - Release Date: 03/11/03
Technical Details
Message-ID: <3fbcb0af@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!fu-berlin.de!newsfeed.news2me.com!newshosting.com!news-xfer1.atl.newshosting.com!nntp-relay.ihug.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10698b,7cb1a3765ebcbeb6,start
X-Google-Attributes: gid10698b,public
X-Google-ArrivalTime: 2003-11-20 04:37:07 PST
Reply-To: "Matthew Cooper" <matthew.cooper@metrodata.co.uk>
From: "Matthew Cooper" <matthew.cooper@metrodata.co.uk>
Newsgroups: borland.public.cppbuilder.database.ado
Subject: Problems with & in commandtext select quiery
Date: Thu, 20 Nov 2003 12:24:40 -0000
Lines: 82
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2600.0000
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000
NNTP-Posting-Host: 212.159.22.22
Message-ID: <3fbcb0af@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1069330607 212.159.22.22 (20 Nov 2003 04:16:47 -0700)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!fu-berlin.de!newsfeed.news2me.com!newshosting.com!news-xfer1.atl.newshosting.com!nntp-relay.ihug.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail