动态创建字段

dtrczx 2002-04-27 05:18:40
谁能指教一个简单问题,在一数据库基础上动态增加或删除来修改字段,并保存,
客户可以自定义字段的名称、类型?
...全文
83 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
jiaxm_xj 2002-09-08
  • 打赏
  • 举报
回复
if not Table1.Exists then begin
with Table1 do 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 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;
dupenf 2002-09-08
  • 打赏
  • 举报
回复
动态在query里写sql语句,就可以啊.
alter yourtable add column newfield type
dejoy 2002-09-08
  • 打赏
  • 举报
回复
直接用alter命令来做,字段名,类型可以由用户选择(不是自定义)。
alter table1 add Column NewField varchar(20)
blazingfire 2002-09-08
  • 打赏
  • 举报
回复
这个用TQuery借助SQL应该不难呀。
alter table1
add Column NewField varchar(20)
然后
TQuery1.ExecSql不就行了嘛

5,939

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧