如何动态创建dbf库以及索引?(100分)

S

scxxf

Unregistered / Unconfirmed
GUEST, unregistred user!
如何动态创建dbf库以及索引?
 
xjgzb 为ADOQUERY

with xjgzb do
begin
close;
sql.Clear;
SQL.Add('Create Table '+table_name);
sql.Add('(ID IDENTITY(1,1) PRIMARY KEY,'+gzb_sql+');');
execSQL;
end;
 
with Table1 do begin
Active := False;
DatabaseName := 'DBDEMOS';
TableType := ttParadox;
TableName := 'CustInfo';

{ Don't overwrite an existing table }

if not Table1.Exists then begin
{ The Table component must not be active }
{ First, describe the type of table and give }
{ it a name }
{ Next, describe the fields in the table }
with FieldDefs do begin
Clear;
with AddFieldDef do begin
Name := 'Field1';
DataType := ftInteger;
Required := True;
end;
with AddFieldDef do begin

Name := 'Field2';
DataType := ftString;
Size := 30;
end;
end;
{ Next, describe any indexes }
with IndexDefs do begin
Clear;
{ The 1st index has no name because it is
{ a Paradox primary key }
with AddIndexDef do begin
Name := '';
Fields := 'Field1';
Options := [ixPrimary];
end;
with AddIndexDef do begin

Name := 'Fld2Indx';
Fields := 'Field2';
Options := [ixCaseInsensitive];
end;
end;
{ Call the CreateTable method to create the table }
CreateTable;
end;
end;
 
楼上的兄弟是创建db库而不是dbf吧!
 
把张剑波的 TableType := ttParadox
改为TableType := ttfoxpro
 
补充一下:

form1.gzjg.First; //gzjg为存入工资结构的表(ID,类别,项目,字段类型,长度 )
tmp_hao:=''; //临时变量,解决“,”用
gzb_sql:=''; //要建立的工资表结构组成
while form1.gzjg.eof=false do
begin
if form1.gzjg.FieldByName('字段类型').asstring='文本' then field_lx:='char'+'('+ form1.gzjg.fieldbyname('字段长度').asstring+')' else field_lx:='money';
gzb_sql:=gzb_sql+tmp_hao+form1.gzjg.fieldbyname('项目').asstring+' '+field_lx;
tmp_hao:=',';
form1.gzjg.Next;
end;

with xjgzb do
begin
close;
sql.Clear;
SQL.Add('Create Table '+table_name);
sql.Add('(ID IDENTITY(1,1) PRIMARY KEY,'+gzb_sql+');');
execSQL;
end;
 
多人接受答案了。
 
顶部