Link to home
Start Free TrialLog in
Avatar of h_mohsenian
h_mohsenian

asked on

Make a Dynamic Database ( Use Alter Table Command from SQL in DELPHI )

I wana make a dynamic DataBase in my program. that means the structure of DataBase( Fields ) can be chnge with User.
This Change Can Make by Some Packages Like DataBase Desktop in Delphi , but I want the User Can Do It In my Program.
For Solving This Problem I used SQL Components, and Do somthing Like This :

Querry1.Close;
Querry1.SQL.Text := 'ALTER TABLE Country ADD column Products char(40)'; //
Querry1.Open;

but it makes Error!

if you Use This Command ('ALTER TABLE') please Help me and if think another way is better please tell me.

Thanks
  h_mohsenian
ASKER CERTIFIED SOLUTION
Avatar of kretzschmar
kretzschmar
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
btw. which database?
Avatar of h_mohsenian
h_mohsenian

ASKER

I had a mistake in typing ,
I wrote This Code in my program:

Querry1.Close;
Querry1.SQL.Text := 'ALTER TABLE Country ADD column Products char(40)'; //
Querry1.Open;

And Querry1.Open & Query1.ExecSql have The Same Result.




And About Your Question : 'which database? '
I Make This DataBase With DataBase Desktop in Delphi And The Database That I Used is 'Paradox 7'
Hello
  Alter table is DDL command, and it's better you use them from the database compoent not from dataset

Database1.Execute('ALTER TABLE Country ADD column Products char(40));

Mohammed
try this

Querry1.Close;
Querry1.SQL.Text := 'ALTER TABLE Country ADD Products char(40)'; //<-keyword coloumn is not needed
Querry1.ExecSQL; //is a must, never use open with an alter statement

meikl ;-)

sorry forget the last quote

Database1.Execute('ALTER TABLE Country ADD column Products char(40)');

also insure this table not used by any other dataset, and the database component  connected property is true

Dear kretzschmar,

as you told The key was Using 'Query1.ExecSql' , not 'Query1.Open' for 'ALTER TABLE'.

But!!!, I Have now a new problem:

when 'Query1.Close' executed 'Query1.Active' Set to 'False', and I 'Alter Table' Works without any problem,
but when I want to Set 'Query1.Active' Again ( Directly or by 'Query1.Open') for setting DBGrid , It Makes Error. What Can I Do?

Thanks
H_MOHSENIAN


Dear mnasman ,

I Have Some problems when I Use Database1 ( Instead of a dataset, like TQuery Type ) .

Please Give Me Your E-Mail.
Dear kretzschmar,

as you told The key was Using 'Query1.ExecSql' , not 'Query1.Open' for 'ALTER TABLE'.

But!!!, I Have now a new problem:

when 'Query1.Close' executed 'Query1.Active' Set to 'False', and I 'Alter Table' Works without any problem,
but when I want to Set 'Query1.Active' Again ( Directly or by 'Query1.Open') for setting DBGrid , It Makes Error. What Can I Do?

Thanks
H_MOHSENIAN


you must replace the sql-text with a select statement before opening the query
Ohh h_mohsenian

I'm late, i saw ur comment after u accept the answer
anyway, here's my email : nasman@mogaza.org
you are welcome to ask any time :)

Mohammed
dear kretzschmar,

you are right and I could solve my problem.
I think you are realy an expert .

Thanks alot
hamed
dear kretzschmar,

you are right and I could solve my problem.
I think you are realy an expert .

Thanks alot
hamed
glad to helped you, hamed
good luck again

meikl ;-)