Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

ADOTable + other files

Posted on 2003-11-03
12
Medium Priority
?
309 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
[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
  • 7
  • 4
12 Comments
 
LVL 25

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 25

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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 25

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
 
LVL 25

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 25

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 25

Expert Comment

by:Tomas Helgi Johannsson
ID: 9685793
Sorry

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

Regards,
  Tomas Helgi
0
 
LVL 25

Accepted Solution

by:
Tomas Helgi Johannsson earned 320 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

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…
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…
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…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

610 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