Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > DB-Aware

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 07-19-2001, 10:20 AM
Joe Joe is offline
Senior Member
 
Join Date: Jul 2001
Posts: 130
Default How can i change the size of a string field in a DBF file ???

Hi,

How can i change the size of a string field in a DBF

file (Table) from my Delphi 5 program ?????

Any help is a big help

Thanks
Reply With Quote
  #2  
Old 07-19-2001, 05:42 PM
manny2463 manny2463 is offline
Member
 
Join Date: Apr 2001
Posts: 60
Default RE: How can i change the size of a string field in a DBF file ???

Since you cannot restructure your table, you have to do the following:
Note: Asumming you have a table named "Employees"
and a field named "LastName" and it's size is 20
and you want to change it to 30

1 - Place a tquery component on a form
2 - Write this code where you want to change the field's size

With Query1 do
begin
sql.clear; // create a temporary field
sql.add('alter table Employees add temp char(30)');
execsql;

sql.clear; // copy contents of lastname to temporary field
sql.add('update Employees set temp = LastName');
execsql;

sql.clear; // delete field lastname
sql.add('alter table Employees drop LastName');
execsql;

sql.clear; // create field lastname with new size
sql.add('alter table Employees add LastName char(30)');
execsql;

sql.clear; // copy contents temporary field to lastname
sql.add('update Employees set LastName = temp');
execsql;

sql.clear; // delete temporary field
sql.add('alter table Employees drop temp');
execsql;
end;

That's all
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 01:44 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.