?
Solved

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

Posted on 2001-07-03
15
Medium Priority
?
418 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 5
  • 3
15 Comments
 
LVL 27

Accepted Solution

by:
kretzschmar earned 300 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
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.

 
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses
Course of the Month9 days, 21 hours left to enroll

762 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