Solved

Creating database

Posted on 2004-09-24
4
125 Views
Last Modified: 2010-04-05
Hi,

Anyone can show me a way how to create Microsoft Aceess database, .mdb file using Delphi code ?

Thanks
0
Comment
Question by:kapot
  • 4
4 Comments
 
LVL 12

Expert Comment

by:esoftbg
ID: 12141970
download a tested example from :
page:        http://www.geocities.com/esoftbg/
  link:        Q_21090790.zip

Emil
0
 
LVL 12

Expert Comment

by:esoftbg
ID: 12141989
procedure TForm1.FormCreate(Sender: TObject);
var
  I:      Integer;
  FN:     string;
  V:      Variant;
  SLTab:  TStringList;
  SLPro:  TStringList;
begin
  FN := ExtractFilePath(Application.ExeName) + 'DATABASE.MDB';
  ConnStr := 'Data Source=' + FN + ';Provider=Microsoft.Jet.OLEDB.4.0';
  if not FileExists(FN) then
  begin
    V := CreateOleObject('ADOX.Catalog');
    V.Create(ConnStr); // Create Database
  end;
  try
    ADOConnection.Close;
    ADOConnection.ConnectionString := ConnStr;
    ADOConnection.Open;

    SLPro := TStringList.Create;
    try
      Memo.Clear;
      AdoConnection.GetProcedureNames(SLPro);
      if (SLPro.IndexOf('PROC_CREATE_WAARDEBONNEN')<0) then
      begin
        ADOCommand.Connection := AdoConnection;
        ADOCommand.CommandText :=' create procedure PROC_CREATE_WAARDEBONNEN as'
                               + ' create table WAARDEBONNEN ('
                               + ' ID AUTOINCREMENT PRIMARY KEY,'
                               + ' GELDIGHEIDSDATUM DATE,'
                               + ' STATUS TEXT(16)'
                               + ')';
        ADOCommand.Execute;
      end;
    finally
      for I := 0 to SLPro.Count-1 do
        Memo.Lines.Add(SLPro.Strings[I]);
      SLPro.Free;
    end;
    SLTab := TStringList.Create;
    try
      AdoConnection.GetTableNames(SLTab);
      if (SLTab.IndexOf('WAARDEBONNEN')<0) then
      begin
        ADOStoredProc.Connection := AdoConnection;
        ADOStoredProc.ProcedureName := 'PROC_CREATE_WAARDEBONNEN';
        ADOStoredProc.ExecProc;
      end;
    finally
      for I := 0 to SLTab.Count-1 do
        Memo.Lines.Add(SLTab.Strings[I]);
      SLTab.Free;
    end;
  finally
    ADOQueryCHANGES.Connection := AdoConnection;
    ADOQueryCHANGES.Active := True;
    ADOQueryCHANGES.FieldByName('ID').Visible := False;
    for I := 1 to 12 do
      cbxMonths.Items.AddObject(ShortMonthNames[I], TObject(I));
    cbxMonths.ItemIndex := Calendar.Month - 1;
    speYear.Value := Calendar.Year;
  end;
end;
0
 
LVL 12

Accepted Solution

by:
esoftbg earned 145 total points
ID: 12267304
Hi kapot,
I posted two answers about your question:
 - 14 minutes after you posted this question I offered a link to a working example;
 -   3 minutes later I posted a piece of code from working example (from the link).

Today 15 days later I would like to know:
  - Have you any problems, can I help you ? I could to change the example if you need it ....

Best regards,
Emil.
0
 
LVL 12

Expert Comment

by:esoftbg
ID: 12635423
I am very surprised !
Here is not only example of how to create a Database, but how to create a Table inside it !
But you grade my solution with B ???? (Almost two months later ....)
That's a big joke, isn't it ?
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now