Article View: borland.public.cppbuilder.database.ado
Article #1352Re: adoquery, access table, why IsEmpty is not true even the table is empty indeed ?
From: frankzyz
Date: Mon, 26 Jul 2004 02:25
Date: Mon, 26 Jul 2004 02:25
110 lines
4370 bytes
4370 bytes
Thank you for your careful reply.
I found there is an hiden rule behind the ADOQuery and SQL :
1) if SQL is like : select * from aTable where condition,
ADOQuery->IsEmpty() will return
properly true, if the table is really empty.
2) if SQL is like : select max(aField) as mx from aTable where condition,
even the table is empry indeed,
ADOQuery->IsEmpty() will return false(ie., the result is not empty) and
record number is 1.
Thank you again.
Frank
"Chemile" <chemile@qwest.net> д���ʼ�
news:4102b55f$1@newsgroups.borland.com...
> I use a different method to find out if a table is empty. I modified some
> code from one of my programs, hopefully this will help you - as its
written
> for an msSQL database.
>
> Test the number of records returned from a query with: pQuery->RecordCount
> Test if a feild is null with:
> if(!VarIsNull(pQuery->FieldValues["Name"])){ }else{ }
> Use the second example if you just want to know the number of records in a
> table, without returning extra data.
>
> ///////////////////////////////////////////////////
>
> AnsiString AqMask = "*", AqTable = "MyTable", AqCol = "MyFeild",
AqSearch
> = "Hello";
> int limit = 999;
>
> TADOQuery *pQuery = new TADOQuery(0);
> pQuery->Connection = ADOConnection1;
> pQuery->CursorType = ctKeyset;
> pQuery->CacheSize = 10000;
> pQuery->CursorLocation = clUseClient;
> pQuery->LockType = ltReadOnly;
>
> pQuery->Close();
> pQuery->SQL->Clear();
> pQuery->SQL->Add("SELECT top " + String(limit) + " " + AqMask + " from
"
> + AqTable + " WHERE LOWER(" + AqCol + ") = LOWER('" +
ParseStream(AqSearch)
> + "')");
> pQuery->Open();
>
> if(pQuery->RecordCount == 0){ ShowMessage("Query Returned Zero
Results!");
> return; }
>
> //Capture Headers//
> AnsiString nLine = "";
> nLine = "";
> for(int tmp = 0; tmp < pQuery->FieldList->Count; tmp++){
> if(nLine != "") nLine = nLine + ",";
> nLine = nLine + "\"" + pQuery->FieldList->Strings[tmp] + "\"";
> }
> Memo1->Lines->Add(nLine);
>
> for(int tmp = 0; tmp < pQuery->RecordCount; tmp++){
> AnsiString pLine = "";
>
> //Get Items//
> pLine = "";
> for(int tmp3 = 0; tmp3 < pQuery->FieldList->Count; tmp3++){
>
if(!VarIsNull(pQuery->FieldValues[pQuery->FieldList->Strings[tmp3]])){
> if(pLine != "") pLine = pLine + ",";
> pLine = pLine + "\"" +
> pQuery->FieldValues[pQuery->FieldList->Strings[tmp3]] + "\"";
> }else{
> if(pLine != "") pLine = pLine + ",";
> pLine = pLine + "\"\"";
> }
> }
> //Use Data Here, Before its Overwritten//
> Memo1->Lines->Add(pLine);
> pQuery->Next();
> }
> }
>
>
>
> ///////////////////////////////////////////////////
>
> TADOQuery *pQuery = new TADOQuery(0);
> pQuery->Connection = ADOConnection1;
> pQuery->CursorType = ctKeyset;
> pQuery->CacheSize = 10000;
> pQuery->CursorLocation = clUseClient;
> pQuery->LockType = ltReadOnly;
>
> pQuery->Close();
> pQuery->SQL->Clear();
> pQuery->SQL->Add("SELECT count (*) from " + AqTable + " WHERE LOWER(" +
> AqCol + ")=LOWER('" + ParseStream(AqSearch) + "')");
> pQuery->Open();
>
> int pCount = pQuery->Fields->Fields[0]->AsInteger;
>
> if(pCount > 0){
> //Put your code here//
> }
>
>
Technical Details
Message-ID:
<41046b96$2@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!213.200.89.82.MISMATCH!tiscali!newsfeed1.ip.tiscali.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<40ffcd9b$1@newsgroups.borland.com> <4102b55f$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10698b,66e2b8def88d26af X-Google-Attributes: gid10698b,public X-Google-Language: ENGLISH,ASCII From: "frankzyz" <frankzyz@etang.com> Newsgroups: borland.public.cppbuilder.database.ado References: <40ffcd9b$1@newsgroups.borland.com> <4102b55f$1@newsgroups.borland.com> Subject: Re: adoquery, access table, why IsEmpty is not true even the table is empty indeed ? Date: Mon, 26 Jul 2004 10:25:24 +0800 Lines: 112 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1437 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 NNTP-Posting-Host: 220.248.133.120 Message-ID: <41046b96$2@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1090808726 220.248.133.120 (25 Jul 2004 19:25:26 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!213.200.89.82.MISMATCH!tiscali!newsfeed1.ip.tiscali.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail