Solved

Creating database

Posted on 2004-09-24
4
123 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
Comment Utility
download a tested example from :
page:        http://www.geocities.com/esoftbg/
  link:        Q_21090790.zip

Emil
0
 
LVL 12

Expert Comment

by:esoftbg
Comment Utility
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
Comment Utility
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
Comment Utility
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

763 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

7 Experts available now in Live!

Get 1:1 Help Now