🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: adoquery, access table, why IsEmpty is not true even the table is empty indeed ?

#1348
From: Chemile
Date: Sat, 24 Jul 2004 19:15
85 lines
3628 bytes
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: <4102b55f$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!news.linkpendium.com!news.linkpendium.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <40ffcd9b$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-7-bit
Reply-To: "Chemile" <chemile@qwest.net>
From: "Chemile" <chemile@qwest.net>
Newsgroups: borland.public.cppbuilder.database.ado
References: <40ffcd9b$1@newsgroups.borland.com>
Subject: Re: adoquery, access table, why IsEmpty is not true even the table is empty indeed ?
Date: Sat, 24 Jul 2004 13:15:42 -0600
Lines: 87
Organization: Avoc Studios
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.3790.0
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.132
NNTP-Posting-Host: 67.171.116.3
Message-ID: <4102b55f$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1090696543 67.171.116.3 (24 Jul 2004 12:15:43 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!news.linkpendium.com!news.linkpendium.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail