动态创建表----大家帮忙呀!谢谢! 我用access2000做好一个数据库aa,我想在一个工程中动态创建一个表bb。请问需要在工程中添加什麽控件连接到数据库aa,之后再怎样写代码动态创建一个表bb!我想动态的(form创建时)在窗体中创建多个edit控件,并且可以根据edit控件的多少来决定form的大小,请问如何实现,谢谢! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 1.acSec: TADOConnection;aqSec: TADOQuery;...procedure TfrmSec.btnAddClick(Sender: TObject);var sSql: string; tName: TStrings;begin tName := TStringList.Create; acSec.GetTableNames(tName, false); if tName.IndexOf('staff') >= 0 then acSec.Execute('drop table staff'); sSql := 'create table staff(ID AutoIncrement Primary Key, ' + //Integer identity; Counter 'sName Text(8) not Null, ' + 'iAge Byte Default 0, ' + 'sCompany Text(32) Null Default "", ' + {虽然在设计表中看到不能为空,实际可以} 'sSalary Decimal(8,2) Default 0, ' + 'bVisible Bit Default True, ' + {是/否} 'sDes Memo Default "", ' + {备注} 'mDate Date Default Date())'; {动态设主键:'alter table stableb add primary key (id)'} aqSec.Close; aqSec.SQL.Text := sSql; try aqSec.ExecSQL; MessageBox(self.Handle, '创建staff成功', '提示', mb_IconInformation + mb_Ok); except MessageBox(self.Handle, 'fail!', '提示', mb_IconInformation + mb_Ok); end; tName.Free;end;2.我没有好办法 请问您一开始定义的acSec: TADOConnection;aqSec: TADOQuery;是什莫意思,是别名吗?谢谢了第二个问题谁能帮我看一下! No.1:ADOQuery.Connection := ADOConnection;//ADOConnection 已经连接with ADOQuery dobegin if Active then Active := False; SQL.Clear; SQL.Add('create table bb(no char(4),name char(8))'; ExecSQL;end;No.2:unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, DB, ADODB, StdCtrls;type TForm1 = class(TForm) ADOQuery1: TADOQuery; Button1: TButton; procedure Button1Click(Sender: TObject); private function GetCount: Integer; procedure SetCount(const Value: Integer); Procedure CreateEdit(vName : String;vLeft,vTop,vHeight,vWidth:Integer;vParent : TWinControl); { Private declarations } public { Public declarations } property FCount :Integer Read GetCount Write SetCount; end;Const FHeight = 21; FWidth = 120;var Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);begin FCount := 13;end;function TForm1.GetCount: Integer;begin //..end;procedure TForm1.SetCount(const Value: Integer);var vIndex : Integer; vTop,vLeft : Integer;begin //.. vTop := 0; vLeft := 0; for vIndex := 0 to Value do begin CreateEdit('Create Edit' + IntToStr(vIndex),vLeft,vTop,FHeight,FWidth,Self); vLeft := vLeft + 125; end; if Self.Width < vLeft + 125 then Self.Width := vLeft + 125 ;end;procedure TForm1.CreateEdit(vName: String; vLeft, vTop, vHeight, vWidth: Integer; vParent: TWinControl);var vEdit : TEdit;begin //.. vEdit := TEdit.Create(Nil); vEdit.Parent := vParent;// vEdit.Left := vLeft; vEdit.Top := vTop; vEdit.Height := vHeight; vEdit.Width := vWidth;end;end. http://community.csdn.net/Expert/topic/3008/3008997.xml?temp=.3814966 请教大哥哥大姐姐一个问题:关于非文本文件的读写 如何防止程序打开两次????? 在delphi7中怎么找不到TNMPOP3、TNMSMTP、HTTP组件啊,请高手指点 ***如何通过delphi进行oracle的备份和恢复操作?另加200分!!!*** 存储过程的问题求教! wsasend返回错误。 【绝对精彩2】大炮打蚂蚁-推荐flash游戏,不比上次推荐的差 我用scrollbox来显示图像,但我想一幅一幅图像往上拉。请问怎么办??在线等!! 如何在两个程序之间传递参数? 关于安装软件的小问题 求助:Dephi直接操作Word文档的问题 有关树的问题,请各位改一下
acSec: TADOConnection;
aqSec: TADOQuery;
...
procedure TfrmSec.btnAddClick(Sender: TObject);
var
sSql: string;
tName: TStrings;
begin
tName := TStringList.Create;
acSec.GetTableNames(tName, false);
if tName.IndexOf('staff') >= 0 then acSec.Execute('drop table staff');
sSql := 'create table staff(ID AutoIncrement Primary Key, ' + //Integer identity; Counter
'sName Text(8) not Null, ' +
'iAge Byte Default 0, ' +
'sCompany Text(32) Null Default "", ' + {虽然在设计表中看到不能为空,实际可以}
'sSalary Decimal(8,2) Default 0, ' +
'bVisible Bit Default True, ' + {是/否}
'sDes Memo Default "", ' + {备注}
'mDate Date Default Date())';
{动态设主键:'alter table stableb add primary key (id)'} aqSec.Close;
aqSec.SQL.Text := sSql;
try
aqSec.ExecSQL;
MessageBox(self.Handle, '创建staff成功', '提示', mb_IconInformation + mb_Ok);
except
MessageBox(self.Handle, 'fail!', '提示', mb_IconInformation + mb_Ok);
end;
tName.Free;
end;2.我没有好办法
ADOQuery.Connection := ADOConnection;//ADOConnection 已经连接
with ADOQuery do
begin
if Active then
Active := False;
SQL.Clear;
SQL.Add('create table bb(no char(4),name char(8))';
ExecSQL;
end;
No.2:
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, ADODB, StdCtrls;type
TForm1 = class(TForm)
ADOQuery1: TADOQuery;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
function GetCount: Integer;
procedure SetCount(const Value: Integer);
Procedure CreateEdit(vName : String;vLeft,vTop,vHeight,vWidth:Integer;vParent : TWinControl);
{ Private declarations }
public
{ Public declarations }
property FCount :Integer Read GetCount Write SetCount;
end;Const
FHeight = 21;
FWidth = 120;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
begin
FCount := 13;
end;function TForm1.GetCount: Integer;
begin
//..
end;procedure TForm1.SetCount(const Value: Integer);
var
vIndex : Integer;
vTop,vLeft : Integer;
begin
//..
vTop := 0;
vLeft := 0;
for vIndex := 0 to Value do
begin
CreateEdit('Create Edit' + IntToStr(vIndex),vLeft,vTop,FHeight,FWidth,Self);
vLeft := vLeft + 125;
end;
if Self.Width < vLeft + 125 then
Self.Width := vLeft + 125 ;
end;procedure TForm1.CreateEdit(vName: String; vLeft, vTop, vHeight,
vWidth: Integer; vParent: TWinControl);
var
vEdit : TEdit;
begin
//..
vEdit := TEdit.Create(Nil);
vEdit.Parent := vParent;//
vEdit.Left := vLeft;
vEdit.Top := vTop;
vEdit.Height := vHeight;
vEdit.Width := vWidth;
end;end.