Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2002
    Location
    Netherlands
    Posts
    5

    Question Unanswered: howto create new msacces table with delphi using SQL ?

    Hi all,

    Could anyone tell me howto create a new table in my MS Acces database
    with the use of a ADOQuery in Delphi ?
    I tried this simple code but nothing happens :

    Code:
    procedure TForm1.Button1Click(Sender: TObject);
    var
      newsql: string;
    begin
      newsql := 'CREATE TABLE models (PBID AUTOINCREMENT primary key,bedrijf varchar not null,adres varchar)';
      with DataModule1 do
      begin
        ADOQuery1.Close;
        ADOQuery1.SQL.Add(newsql);
      end;
    end;
    I can browse my data in other tables in the same database, so i guess the connection works fine.
    Do i need to do something else ?

    Thanks,
    Jimmy

  2. #2
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    Uh... you never execute the query?
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  3. #3
    Join Date
    Nov 2002
    Location
    Netherlands
    Posts
    5
    Hi Teddy,

    Sorry for my late reaction but i got ill

    I added the line : ADOQuery1.ExecSQL;
    to my code to execute my SQL query so no my code looks like this :
    Code:
    procedure TForm1.Button1Click(Sender: TObject);
    var
      newsql: string;
    begin
      newsql := 'CREATE TABLE models (PBID AUTOINCREMENT primary key,bedrijf varchar not null,adres varchar)';
      with DataModule1 do
      begin
        ADOQuery1.Close;
        ADOQuery1.SQL.Add(newsql);
        ADOQuery1.ExecSQL;
      end;
    end;
    But then i get an error message saying my
    CREATE TABLE has a syntax error.
    I don't understand why ... is there something wrong with my syntax?
    This is the SQL syntax i am using :

    CREATE TABLE models (PBID AUTOINCREMENT primary key,bedrijf varchar not null,adres varchar)

    I am using MS Office 2003 Acces (but i must be compatible with Office XP Acces also )

    Any idea's ?

    Cheers!
    Last edited by hendrixx; 06-27-04 at 19:36.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •