• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 311
  • Last Modified:

ADOTable + other files

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
fradolcino
Asked:
fradolcino
  • 7
  • 4
1 Solution
 
Tomas Helgi JohannssonCommented:
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
 
fradolcinoAuthor Commented:
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
 
Tomas Helgi JohannssonCommented:
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
Tomas Helgi JohannssonCommented:
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
 
DeerBearCommented:
Hi,

Have also a look to ForceDirectory API.

HTH,

Andrew
0
 
fradolcinoAuthor Commented:
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
 
Tomas Helgi JohannssonCommented:
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
 
fradolcinoAuthor Commented:
Ok but
TableType := ttParadox;
I have MICROSOFT ACCES DATABASE (mdb)
How can i adapt this
Thanks
0
 
fradolcinoAuthor Commented:
I use ADOTables
Thanks again
0
 
Tomas Helgi JohannssonCommented:
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
 
Tomas Helgi JohannssonCommented:
Sorry

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

Regards,
  Tomas Helgi
0
 
Tomas Helgi JohannssonCommented:
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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 7
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now