Solved

ADOTable + other files

Posted on 2003-11-03
12
303 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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Intraweb submit form as a POST request 4 303
Convert Jpg /PNG To GIF 5 135
Dev Express grid collapse 2 44
tvirtualstringtree freeze when load too manny images 10 62
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…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

770 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