Solved

ADOTable + other files

Posted on 2003-11-03
12
296 Views
Last Modified: 2010-04-05
I have a lot of customers
When i add a new one i want to make something like this
Create a subdirectory with the specified name
In subdirectory create a database with the same name with structure (name, adress, phonenumber)
Example
i add the name John Doe
in c:\temp make subdurectory JohnDoe
in c:\temp\JohnDoe\ make johndoe.mdb with the structure below
is it possible
Thanks
0
Comment
Question by:fradolcino
  • 7
  • 4
12 Comments
 
LVL 24

Expert Comment

by:Tomas Helgi Johannsson
ID: 9671813
Yes this is possible.
There are several things that you have to take into considerations and do in the right order
1) Create the subdirectory
2) Create the databasefile or copy an existing database file to the subdirectory.
3) Create a ADOConnection for each customer and let the path in the connection string point to the subdirectory.
                                                                          ======================================
4) Create all necissary ADOTable objects and connect them to the ADOConnection.


Regards,
  Tomas Helg
0
 

Author Comment

by:fradolcino
ID: 9676780
Ok, but i want to make all of that by Delphi
And i want some source codes, the steps below i already know
Thanks
0
 
LVL 24

Expert Comment

by:Tomas Helgi Johannsson
ID: 9677077
Here you have some source code (a very simple solution :).
You can manage the connections by having lists or arrays of TADOConnection and TADOTable or put the connection and tables  into a TDataModule and create functions there which does the nessisary creations.
Example: Overide the Create constructor of the TDataModule and have the the path as a variable. In that constructor do the nessisary connections like this code sample does.

Regards,
  Tomas Helgi
------ code below ---------------------------

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Grids, DBGrids, Db, ADODB, StdCtrls;

type
  TForm1 = class(TForm)
    ADOConnection1: TADOConnection;
    Button1: TButton;
    DataSource1: TDataSource;
    ADOTable1: TADOTable;
    DBGrid1: TDBGrid;
    procedure Button1Click(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    { Private declarations }
    myCon : TAdoConnection;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var
  userpath : String;
begin
  userpath := 'C:\Temp\test.mdb';
  myCon := TADOConnection.Create(self);
  myCon.ConnectionString := 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+ userpath+';Persist Security Info=False';
  myCon.KeepConnection := true;
  myCon.LoginPrompt := false;
  myCon.Open;
  ADOTable1.Connection := myCon;
  ADOTable1.TableName := 'Authors';
  ADOTable1.Open;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  if myCon <> nil then
  begin
  myCon.Close;
  myCon.Free;
  end;
end;

end.
0
 
LVL 24

Expert Comment

by:Tomas Helgi Johannsson
ID: 9677144
Here is some code for the creation of directories

if not DirectoryExists('c:\temp') then
    if not CreateDir('C:\temp') then
    raise Exception.Create('Cannot create c:\temp');

--------------------------------------------------------------

0
 
LVL 5

Expert Comment

by:DeerBear
ID: 9677824
Hi,

Have also a look to ForceDirectory API.

HTH,

Andrew
0
 

Author Comment

by:fradolcino
ID: 9685302
Ok
So far so good
But perhaps i was not absolutely clear
I have a database (an acces database mdb) Base1.mdb
In data base i want to create tabels (with this structure name,adress,phonenumber)
Tabels must have the person name
i want to create them by Delphi not manual
Thanks
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 24

Expert Comment

by:Tomas Helgi Johannsson
ID: 9685353
I think this is what you are looking for.
This example is under TDataSet.FieldDefs in the Delphi Help file

if not Table1.Exists then begin
  with Table1 do begin
    { The Table component must not be active }
    Active := False;  
    { First, describe the type of table and give }
    { it a name }
    DatabaseName := 'DBDEMOS';  
    TableType := ttParadox;
    TableName := 'CustInfo';
    { Next, describe the fields in the table }
    with FieldDefs do begin
      Clear;
      with AddFieldDef do begin

        Name := 'Field1';
        DataType := ftInteger;
        Required := True;
      end;
      with AddFieldDef do begin
        Name := 'Field2';
        DataType := ftString;
        Size := 30;
      end;
    end;
    { Next, describe any indexes }
    with IndexDefs do begin
      Clear;
      { The 1st index has no name because it is
      { a Paradox primary key }
      with AddIndexDef do begin

        Name := '';
        Fields := 'Field1';
        Options := [ixPrimary];
      end;
      with AddIndexDef do begin
        Name := 'Fld2Indx';
        Fields := 'Field2';
        Options := [ixCaseInsensitive];
      end;
    end;
    { Call the CreateTable method to create the table }
    CreateTable;
  end;
end;


Hope this helps.

Regards,
  Tomas Helgi
0
 

Author Comment

by:fradolcino
ID: 9685553
Ok but
TableType := ttParadox;
I have MICROSOFT ACCES DATABASE (mdb)
How can i adapt this
Thanks
0
 

Author Comment

by:fradolcino
ID: 9685670
I use ADOTables
Thanks again
0
 
LVL 24

Expert Comment

by:Tomas Helgi Johannsson
ID: 9685760
Hmm, you could also use TADOQuery and create the table like this

in the SQL put

CREATE TABLE :usertable ( name varchar(50), address varchar(50), phonenumber varchar(20));


and then

begin
......
  TADOQuery1.ParamByName('usertable').Value := username;
  TADOQuery1.ExecSQL;
.....
end;


Regards,
  Tomas Helgi

0
 
LVL 24

Expert Comment

by:Tomas Helgi Johannsson
ID: 9685793
Sorry

ADOQuery1.Parameters.ParamByName('usertable').Value := username;
ADOQuery1.ExecSQL;

Regards,
  Tomas Helgi
0
 
LVL 24

Accepted Solution

by:
Tomas Helgi Johannsson earned 80 total points
ID: 9685854
Sorry again ;)

Some brain overload at my work :(

CREATE TABLE  :usertable ( name TEXT(50), address TEXT(50), phonenumber TEXT(20));

Regards,
  Tomas Helgi
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

746 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

14 Experts available now in Live!

Get 1:1 Help Now