Solved

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

Posted on 2001-07-03
15
391 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
 
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:mnasman
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:mnasman
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now