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
Solved

Creating database

Posted on 2004-09-24
4
126 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

856 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