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

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
0
h_mohsenian
Asked:
h_mohsenian
  • 7
  • 5
  • 3
1 Solution
 
kretzschmarCommented:
Query1.Close;
Query1.SQL.Text := 'ALTER TABLE Country ADD column Products char(40)'; //
Query1.ExecSql; //<- use this, if your statement do not return any results, like update, insert or alter

meikl ;-)
0
 
kretzschmarCommented:
btw. which database?
0
 
h_mohsenianAuthor Commented:
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.




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.

 
h_mohsenianAuthor Commented:
And About Your Question : 'which database? '
I Make This DataBase With DataBase Desktop in Delphi And The Database That I Used is 'Paradox 7'
0
 
Mohammed NasmanSoftware DeveloperCommented:
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
0
 
kretzschmarCommented:
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 ;-)

0
 
Mohammed NasmanSoftware DeveloperCommented:
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

0
 
h_mohsenianAuthor Commented:
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


0
 
h_mohsenianAuthor Commented:
Dear mnasman ,

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

Please Give Me Your E-Mail.
0
 
h_mohsenianAuthor Commented:
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


0
 
kretzschmarCommented:
you must replace the sql-text with a select statement before opening the query
0
 
Mohammed NasmanSoftware DeveloperCommented:
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
0
 
h_mohsenianAuthor Commented:
dear kretzschmar,

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

Thanks alot
hamed
0
 
h_mohsenianAuthor Commented:
dear kretzschmar,

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

Thanks alot
hamed
0
 
kretzschmarCommented:
glad to helped you, hamed
good luck again

meikl ;-)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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