如何取得动态创建的数据表的所有字段名 ?(50分)

J

joinrry

Unregistered / Unconfirmed
GUEST, unregistred user!
本人在数据库编程中,用table控件动态创建了一个数据表格,代码如下:if not Table1.Exists then
begin
with Table1do
begin
{ The Table component must not be active }
Active := False;
{ First, describe the type of table and give }
{ it a name }
DatabaseName := 'DBDEMOS';
TableType := ttParadox;
TableName := 'CustInfo';
{ Next, describe the fields in the table }
with FieldDefsdo
begin
Clear;
with AddFieldDefdo
begin
Name := 'Field1';
DataType := ftInteger;
Required := True;
end;
with AddFieldDefdo
begin
Name := 'Field2';
DataType := ftString;
Size := 30;
end;
end;
{ Next, describe any indexes }
with IndexDefsdo
begin
Clear;
{ The 1st index has no name because it is
{ a Paradox primary key }
with AddIndexDefdo
begin

Name := '';
Fields := 'Field1';
Options := [ixPrimary];
end;
with AddIndexDefdo
begin
Name := 'Fld2Indx';
Fields := 'Field2';
Options := [ixCaseInsensitive];
end;
end;
{ Call the CreateTable method to create the table }
CreateTable;
end;
end;

但是到了要编查询功能的时候,需要获得数据表的所有字段,但一直未能如愿,请教!!!!!!!!★
 
利用TSession的几个函数可以搞定。
 
用Select * from tablename
不就可以获得所有字段,
然后用Query.fields[n].fieldname可获得字段名,count可获得个数。
 
1.Field个数:table1.FieldCount-1.
2.Field名字:table1.FieldDefs.Items.Name,i指第i个field.
 
各样大虾,谢谢了!
 
同意ybcheng用TSession
 
用Select * from tablename
不就可以获得所有字段,
然后用Query.fields[n].fieldname可获得字段名,count可获得个数。
 
多人接受答案了。
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
501
import
I
I
回复
0
查看
602
import
I
顶部