Solved

ADOTable + other files

Posted on 2003-11-03
12
304 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 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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.

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Title # Comments Views Activity
Best Firemonkey component pack 1 119
Unique identifier on a terminal server (rdp) 4 67
Base1 Encode/Decode 3 82
Tidtcpserver listening on multiports? 1 35
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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
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…

830 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