🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

How do I submit an SQL statement to an Access database using code?

#2173
From: Ted Byers
Date: Fri, 31 Oct 2003 17:31
53 lines
3386 bytes
I am using BCB5Pro for this.

Here is my "New" event handler so far (along with a trivial table
definition, for test purposes):

void __fastcall TCookbookMainForm::New1Click(TObject *Sender)
{
  if(OpenDialog->Execute()) {
    if(FileExists(OpenDialog->FileName)) {
      ShowMessage("File exist and will be recreated");
      DeleteFile(OpenDialog->FileName);
    }
    RecipeCatalog=Variant::CreateObject("ADOX.Catalog");;
    RecipeCatalog.Exec(Function("Create") <<
              ("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source="+OpenDialog->FileName));
    AnsiString SQLstatement("CREATE TABLE JUNK( NDX INTEGER NOT NULL,
NAMEVALUE VARCHAR(60) NOT NULL )");
  }
}

How to I send the SQLstatement to the new Access database?

Also, can anyone show me the syntax for creating using SQL an AutoNumber
field to be used as an index and as a link between two tables (presumably
within a CREATE SCHEMA statement), and how such a pair of tables is updated?
That is, suppose I want two tables, one of which gives each possible
ingredient for recipes an index number and the second uses these index
numbers to identify the ingredients used within each recipe (obviously
neither field can be NULL), and that I have a form on which there is a table
into which ingredients and instructions for a recipe can be entered (and, of
course, all ingredient indices must exist in the ingredients table).  And,
of course, for the ingredients table, all values in both fields MUST be
unique!  Populating such a form FROM an existing database is not a problem
(i.e. I already have code to do it), but creating a NEW database with the
right structure (i.e. so the user can keep recipes for Chinese cuisine
separate from recipes for Greek cuisine) and sending user supplied data to
it is something I haven't quite figured out.

I don't know, yet, but I believe it should be possible to handle ALL of this
through SQL code, but I don't kow SQL well enough to produce it quickly.  If
I am right, then the answer to my first question along with some sample SQL
would solve the remaining issues I have with this project.  A head start
would therefore be appreciated.

One constraint to how I approach this is that I do not want my program to be
dependant on any DLLs other than what ships with Windows!  Not do I want it
dependant on BDE (even if it is possible to link with BDE in such a way that
I wouldn't have to ship extra DLLs).

Thanks for your time.

Ted
Technical Details
Message-ID: <3fa29d35$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10698b,d26ef4716ff1429f,start
X-Google-Attributes: gid10698b,public
X-Google-ArrivalTime: 2003-10-31 09:39:49 PST
From: "Ted Byers" <r.ted.byers@sympatico.ca>
Newsgroups: borland.public.cppbuilder.database.ado
Subject: How do I submit an SQL statement to an Access database using code?
Date: Fri, 31 Oct 2003 12:31:59 -0500
Lines: 55
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: 65.95.126.104
Message-ID: <3fa29d35$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1067621685 65.95.126.104 (31 Oct 2003 09:34:45 -0700)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail