Solved

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

Posted on 2001-07-03
15
401 Views
Last Modified: 2010-04-06
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
Comment
Question by:h_mohsenian
  • 7
  • 5
  • 3
15 Comments
 
LVL 27

Accepted Solution

by:
kretzschmar earned 100 total points
ID: 6248216
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
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6248220
btw. which database?
0
 
LVL 1

Author Comment

by:h_mohsenian
ID: 6248299
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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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 1

Author Comment

by:h_mohsenian
ID: 6248319
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
 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 6248359
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
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6248362
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
 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 6248375
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
 
LVL 1

Author Comment

by:h_mohsenian
ID: 6249051
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
 
LVL 1

Author Comment

by:h_mohsenian
ID: 6249075
Dear mnasman ,

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

Please Give Me Your E-Mail.
0
 
LVL 1

Author Comment

by:h_mohsenian
ID: 6249081
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
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6249308
you must replace the sql-text with a select statement before opening the query
0
 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 6249819
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
 
LVL 1

Author Comment

by:h_mohsenian
ID: 6251514
dear kretzschmar,

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

Thanks alot
hamed
0
 
LVL 1

Author Comment

by:h_mohsenian
ID: 6251544
dear kretzschmar,

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

Thanks alot
hamed
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6251653
glad to helped you, hamed
good luck again

meikl ;-)
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…

828 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