?
Solved

Creating database

Posted on 2004-09-24
4
Medium Priority
?
132 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 435 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses
Course of the Month13 days, 6 hours left to enroll

800 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