能在Access中动态创建表吗 能,但要用TQUERYSQL语句你会吧,那就行了BYE 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 adoquery1.SQL.Text := 'create table test_table3 (id integer null,name string(20) null,mytime time null)'; 不行,有提示不支持creat语句 不是,说了吗?用TQUERY行ADOQUERY不行,他不支持,表级操作看看,ADO的层次结构就知道了 用ADOX,详情在李维书第三本131页以后代码如下参考一下吧:unit fADOXDemoMain;interfaceuses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, Db, ADODB, StdCtrls, Grids, ComCtrls, OleServer, ADOX_TLB, ExtCtrls;type TfrmMain = class(TForm) ADOConnection1: TADOConnection; btnOpenSchema: TButton; btnTables: TButton; btnFields: TButton; PageControl1: TPageControl; TabSheet1: TTabSheet; TabSheet2: TTabSheet; TabSheet3: TTabSheet; sgFields: TStringGrid; sgIndexes: TStringGrid; sgStoredProcs: TStringGrid; Panel1: TPanel; pcMain: TPageControl; TabSheet4: TTabSheet; TabSheet5: TTabSheet; lbDatabases: TListBox; lbTables: TListBox; btnIndexes: TButton; btnSP: TButton; btnCreateTable: TButton; btnDelete: TButton; procedure btnOpenSchemaClick(Sender: TObject); procedure FormCreate(Sender: TObject); procedure FormDestroy(Sender: TObject); procedure btnTablesClick(Sender: TObject); procedure btnFieldsClick(Sender: TObject); procedure btnIndexesClick(Sender: TObject); procedure btnSPClick(Sender: TObject); procedure btnCreateTableClick(Sender: TObject); procedure btnDeleteClick(Sender: TObject); private { Private declarations } adoxCatalog : _Catalog; adoxTables : Tables; adoxTable : _Table; adoxColumns : Columns; adoxColumn : _Column; adoxIndexes : Indexes; adoxIndex : _Index; adoxSPs : Procedures; adoxSP : Procedure_; iCol : Integer; iRow : Integer; procedure ShowStoredProceduresInfos; procedure ShowIndexInfos; procedure ClearCells(aCell : TStringGrid); function GetADOXFieldType(aType : DataTypeEnum): String; procedure ShowFieldInfos; procedure ShowTableInfos; public { Public declarations } end;var frmMain: TfrmMain;implementationuses fCreateTable;{$R *.DFM}procedure TfrmMain.btnOpenSchemaClick(Sender: TObject);var iCount : integer; aTableList : TStringList;begin try aTableList := TStringList.Create; ADOConnection1.GetTableNames(aTableList, False); for iCount := 0 to aTableList.Count - 1 do // Iterate begin lbDatabases.Items.Add(aTableList.Strings[iCount]); end; // for finally // wrap up aTableList.Free; pcMain.ActivePageIndex := 0; end; // try/finallyend;procedure TfrmMain.FormCreate(Sender: TObject);begin adoxCatalog := CoCatalog.Create;end;procedure TfrmMain.FormDestroy(Sender: TObject);begin adoxCatalog := nil;end;procedure TfrmMain.btnTablesClick(Sender: TObject);var iCount: Integer;begin adoxCatalog.Set_ActiveConnection(ADOConnection1.ConnectionObject); adoxTables := adoxCatalog.Tables; lbTables.Clear; for iCount := 0 to adoxTables.Count - 1 do // Iterate begin adoxTable := adoxTables.Item[iCount]; ShowTableInfos; end; // for lbTables.ItemIndex := 0; pcMain.ActivePageIndex := 1;end;procedure TfrmMain.ShowTableInfos;begin lbTables.Items.Add(adoxTable.Name);end;procedure TfrmMain.ShowFieldInfos;var iCount: Integer;begin adoxColumns := adoxTable.Columns; ClearCells(sgFields); iCol := 0; iRow := 0; sgFields.Cells[iCol, iRow] := '逆嘿'; Inc(iCol); sgFields.Cells[iCol, iRow] := '逆篈'; Inc(iRow); iCol := 0; for iCount := 0 to adoxColumns.Count - 1 do // Iterate begin adoxColumn := adoxColumns.Item[iCount]; sgFields.Cells[iCol, iRow] := adoxColumn.Name; Inc(iCol); sgFields.Cells[iCol, iRow] := GetADOXFieldType(adoxColumn.Type_); Inc(iRow); iCol := 0; end; // forend;function TfrmMain.GetADOXFieldType(aType : DataTypeEnum): String;begin case aType of // adEmpty : Result := 'adEmpty'; adTinyInt : Result := 'adTinyInt'; adSmallInt : Result := 'adSmallInt'; adInteger : Result := 'adInteger'; adBigInt : Result := 'adBigInt'; adUnsignedTinyInt : Result := 'adUnsignedTinyInt'; adUnsignedSmallInt : Result := 'adUnsignedSmallInt'; adUnsignedInt : Result := 'adUnsignedInt'; adUnsignedBigInt : Result := 'adUnsignedBigInt'; adSingle : Result := 'adSingle'; adDouble : Result := 'adDouble'; adCurrency : Result := 'adCurrency'; adDecimal : Result := 'adDecimal'; adNumeric : Result := 'adNumeric'; adBoolean : Result := 'adBoolean'; adError : Result := 'adError'; adUserDefined : Result := 'adUserDefined'; adVariant : Result := 'adVariant'; adIDispatch : Result := 'adIDispatch'; adIUnknown : Result := 'adIUnknown'; adGUID : Result := 'adGUID'; adDate : Result := 'adDate'; adDBDate : Result := 'adDBDate'; adDBTime : Result := 'adDBTime'; adDBTimeStamp : Result := 'adDBTimeStamp'; adBSTR : Result := 'adBSTR'; adChar : Result := 'adChar'; adVarChar : Result := 'adVarChar'; adLongVarChar : Result := 'adLongVarChar'; adWChar : Result := 'adWChar'; adVarWChar : Result := 'adVarWChar'; adLongVarWChar : Result := 'adLongVarWChar'; adBinary : Result := 'adBinary'; adVarBinary : Result := 'adVarBinary'; adLongVarBinary : Result := 'adLongVarBinary'; adChapter : Result := 'adChapter'; adFileTime : Result := 'adFileTime'; adPropVariant : Result := 'adPropVariant'; adVarNumeric : Result := 'adVarNumeric'; end; // caseend;procedure TfrmMain.btnFieldsClick(Sender: TObject);begin pcMain.ActivePageIndex := 1; adoxTable := adoxTables.Item[lbTables.ItemIndex]; ShowFieldInfos;end;procedure TfrmMain.ClearCells(aCell : TStringGrid);var iCount1: Integer; iCount: Integer;begin for iCount := 0 to sgFields.RowCount - 1 do // Iterate begin for iCount1 := 0 to sgFields.ColCount - 1 do // Iterate begin aCell.Cells[iCount1, iCount] := ''; end; // for end; // forend;procedure TfrmMain.btnIndexesClick(Sender: TObject);begin pcMain.ActivePageIndex := 1; adoxTable := adoxTables.Item[lbTables.ItemIndex]; ShowIndexInfos;end;procedure TfrmMain.ShowIndexInfos;var iCount: Integer; iCount1: Integer;begin adoxIndexes := adoxTable.Indexes; ClearCells(sgIndexes); iCol := 0; iRow := 0; sgIndexes.Cells[iCol, iRow] := 'ま嘿'; Inc(iCol); sgIndexes.Cells[iCol, iRow] := 'Clustered'; Inc(iCol); sgIndexes.Cells[iCol, iRow] := 'Primary'; Inc(iCol); sgIndexes.Cells[iCol, iRow] := '逆'; Inc(iRow); iCol := 0; for iCount := 0 to adoxIndexes.Count - 1 do // Iterate begin adoxIndex := adoxIndexes.Item[iCount]; sgIndexes.Cells[iCol, iRow] := adoxIndex.Name; Inc(iCol); if (adoxIndex.Clustered) then sgIndexes.Cells[iCol, iRow] := '琌' else sgIndexes.Cells[iCol, iRow] := ''; Inc(iCol); if (adoxIndex.PrimaryKey) then sgIndexes.Cells[iCol, iRow] := '琌' else sgIndexes.Cells[iCol, iRow] := ''; Inc(iCol); adoxColumns := adoxIndex.Columns; for iCount1 := 0 to adoxColumns.Count - 1 do // Iterate begin adoxColumn := adoxColumns.Item[iCount1]; sgIndexes.Cells[iCol, iRow] := sgIndexes.Cells[iCol, iRow] + ' : ' + adoxColumn.Name; end; // for Inc(iRow); iCol := 0; end; // forend;procedure TfrmMain.btnSPClick(Sender: TObject);var iCount: Integer;begin adoxSPs := adoxCatalog.Procedures; ClearCells(sgStoredProcs); iCol := 0; iRow := 0; sgStoredProcs.Cells[iCol, iRow] := '箇纗祘嘿'; Inc(iCol); sgStoredProcs.Cells[iCol, iRow] := 'ミら戳'; Inc(iRow); for iCount := 0 to adoxSPs.Count - 1 do // Iterate begin adoxSP := adoxSPs.Item[iCount]; ShowStoredProceduresInfos; end; // forend;procedure TfrmMain.ShowStoredProceduresInfos;var iCount: Integer;begin iCol := 0; sgStoredProcs.Cells[iCol, iRow] := adoxSP.Name; Inc(iCol); sgStoredProcs.Cells[iCol, iRow] := VarToStr(adoxSP.DateCreated); Inc(iRow);end;procedure TfrmMain.btnCreateTableClick(Sender: TObject);begin try frmCreateTable := TfrmCreateTable.Create(Self); frmCreateTable.SetCatalog(adoxCatalog); frmCreateTable.SetConnectionString(ADOConnection1.ConnectionString); frmCreateTable.ShowModal; finally // wrap up frmCreateTable.Free; end; // try/finallyend;procedure TfrmMain.btnDeleteClick(Sender: TObject);begin adoxTables := adoxCatalog.Tables; adoxTables.Delete(lbTables.Items[lbTables.ItemIndex]);end;end. dbgrideh的光标定位问题 默林老人在系统中哪个文件夹? 高人指点 delphi 中 怎样给一个的新建button 加上图标?(求详解) delphi3下的自定义控件可否在DELPHI5或6或7上使用? 用ADODataSet取出的数据,还能不能再进行排序? 关于pagecontrol的按钮问题 这样的SQL怎么写?急 安装Sql server 2000的问题 一个关于commandtext动态赋值的问题 Delphi新手特来送分,先到先得... 个人仿制OICQ的通讯软件,供企业内部网和工作组使用。请帮忙测试! DBEdit的OnKeyDown事件,空格键的屏蔽?
用TQUERY行
ADOQUERY不行,他不支持,表级操作
看看,ADO的层次结构就知道了
unit fADOXDemoMain;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Db, ADODB, StdCtrls, Grids, ComCtrls, OleServer, ADOX_TLB, ExtCtrls;type
TfrmMain = class(TForm)
ADOConnection1: TADOConnection;
btnOpenSchema: TButton;
btnTables: TButton;
btnFields: TButton;
PageControl1: TPageControl;
TabSheet1: TTabSheet;
TabSheet2: TTabSheet;
TabSheet3: TTabSheet;
sgFields: TStringGrid;
sgIndexes: TStringGrid;
sgStoredProcs: TStringGrid;
Panel1: TPanel;
pcMain: TPageControl;
TabSheet4: TTabSheet;
TabSheet5: TTabSheet;
lbDatabases: TListBox;
lbTables: TListBox;
btnIndexes: TButton;
btnSP: TButton;
btnCreateTable: TButton;
btnDelete: TButton;
procedure btnOpenSchemaClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure btnTablesClick(Sender: TObject);
procedure btnFieldsClick(Sender: TObject);
procedure btnIndexesClick(Sender: TObject);
procedure btnSPClick(Sender: TObject);
procedure btnCreateTableClick(Sender: TObject);
procedure btnDeleteClick(Sender: TObject);
private
{ Private declarations }
adoxCatalog : _Catalog;
adoxTables : Tables;
adoxTable : _Table;
adoxColumns : Columns;
adoxColumn : _Column;
adoxIndexes : Indexes;
adoxIndex : _Index;
adoxSPs : Procedures;
adoxSP : Procedure_;
iCol : Integer;
iRow : Integer; procedure ShowStoredProceduresInfos;
procedure ShowIndexInfos;
procedure ClearCells(aCell : TStringGrid);
function GetADOXFieldType(aType : DataTypeEnum): String;
procedure ShowFieldInfos;
procedure ShowTableInfos;
public
{ Public declarations }
end;var
frmMain: TfrmMain;implementationuses fCreateTable;{$R *.DFM}procedure TfrmMain.btnOpenSchemaClick(Sender: TObject);
var
iCount : integer;
aTableList : TStringList;
begin
try
aTableList := TStringList.Create;
ADOConnection1.GetTableNames(aTableList, False);
for iCount := 0 to aTableList.Count - 1 do // Iterate
begin
lbDatabases.Items.Add(aTableList.Strings[iCount]);
end; // for
finally // wrap up
aTableList.Free;
pcMain.ActivePageIndex := 0;
end; // try/finally
end;procedure TfrmMain.FormCreate(Sender: TObject);
begin
adoxCatalog := CoCatalog.Create;
end;procedure TfrmMain.FormDestroy(Sender: TObject);
begin
adoxCatalog := nil;
end;procedure TfrmMain.btnTablesClick(Sender: TObject);
var
iCount: Integer;
begin
adoxCatalog.Set_ActiveConnection(ADOConnection1.ConnectionObject);
adoxTables := adoxCatalog.Tables;
lbTables.Clear;
for iCount := 0 to adoxTables.Count - 1 do // Iterate
begin
adoxTable := adoxTables.Item[iCount];
ShowTableInfos;
end; // for
lbTables.ItemIndex := 0;
pcMain.ActivePageIndex := 1;
end;procedure TfrmMain.ShowTableInfos;
begin
lbTables.Items.Add(adoxTable.Name);
end;procedure TfrmMain.ShowFieldInfos;
var
iCount: Integer;
begin
adoxColumns := adoxTable.Columns;
ClearCells(sgFields);
iCol := 0;
iRow := 0;
sgFields.Cells[iCol, iRow] := '逆嘿';
Inc(iCol);
sgFields.Cells[iCol, iRow] := '逆篈';
Inc(iRow);
iCol := 0;
for iCount := 0 to adoxColumns.Count - 1 do // Iterate
begin
adoxColumn := adoxColumns.Item[iCount];
sgFields.Cells[iCol, iRow] := adoxColumn.Name;
Inc(iCol);
sgFields.Cells[iCol, iRow] := GetADOXFieldType(adoxColumn.Type_);
Inc(iRow);
iCol := 0;
end; // for
end;function TfrmMain.GetADOXFieldType(aType : DataTypeEnum): String;
begin
case aType of //
adEmpty : Result := 'adEmpty';
adTinyInt : Result := 'adTinyInt';
adSmallInt : Result := 'adSmallInt';
adInteger : Result := 'adInteger';
adBigInt : Result := 'adBigInt';
adUnsignedTinyInt : Result := 'adUnsignedTinyInt';
adUnsignedSmallInt : Result := 'adUnsignedSmallInt';
adUnsignedInt : Result := 'adUnsignedInt';
adUnsignedBigInt : Result := 'adUnsignedBigInt';
adSingle : Result := 'adSingle';
adDouble : Result := 'adDouble';
adCurrency : Result := 'adCurrency';
adDecimal : Result := 'adDecimal';
adNumeric : Result := 'adNumeric';
adBoolean : Result := 'adBoolean';
adError : Result := 'adError';
adUserDefined : Result := 'adUserDefined';
adVariant : Result := 'adVariant';
adIDispatch : Result := 'adIDispatch';
adIUnknown : Result := 'adIUnknown';
adGUID : Result := 'adGUID';
adDate : Result := 'adDate';
adDBDate : Result := 'adDBDate';
adDBTime : Result := 'adDBTime';
adDBTimeStamp : Result := 'adDBTimeStamp';
adBSTR : Result := 'adBSTR';
adChar : Result := 'adChar';
adVarChar : Result := 'adVarChar';
adLongVarChar : Result := 'adLongVarChar';
adWChar : Result := 'adWChar';
adVarWChar : Result := 'adVarWChar';
adLongVarWChar : Result := 'adLongVarWChar';
adBinary : Result := 'adBinary';
adVarBinary : Result := 'adVarBinary';
adLongVarBinary : Result := 'adLongVarBinary';
adChapter : Result := 'adChapter';
adFileTime : Result := 'adFileTime';
adPropVariant : Result := 'adPropVariant';
adVarNumeric : Result := 'adVarNumeric';
end; // case
end;procedure TfrmMain.btnFieldsClick(Sender: TObject);
begin
pcMain.ActivePageIndex := 1;
adoxTable := adoxTables.Item[lbTables.ItemIndex];
ShowFieldInfos;
end;procedure TfrmMain.ClearCells(aCell : TStringGrid);
var
iCount1: Integer;
iCount: Integer;
begin
for iCount := 0 to sgFields.RowCount - 1 do // Iterate
begin
for iCount1 := 0 to sgFields.ColCount - 1 do // Iterate
begin
aCell.Cells[iCount1, iCount] := '';
end; // for
end; // for
end;procedure TfrmMain.btnIndexesClick(Sender: TObject);
begin
pcMain.ActivePageIndex := 1;
adoxTable := adoxTables.Item[lbTables.ItemIndex];
ShowIndexInfos;
end;procedure TfrmMain.ShowIndexInfos;
var
iCount: Integer;
iCount1: Integer;
begin
adoxIndexes := adoxTable.Indexes;
ClearCells(sgIndexes);
iCol := 0;
iRow := 0;
sgIndexes.Cells[iCol, iRow] := 'ま嘿';
Inc(iCol);
sgIndexes.Cells[iCol, iRow] := 'Clustered';
Inc(iCol);
sgIndexes.Cells[iCol, iRow] := 'Primary';
Inc(iCol);
sgIndexes.Cells[iCol, iRow] := '逆';
Inc(iRow);
iCol := 0;
for iCount := 0 to adoxIndexes.Count - 1 do // Iterate
begin
adoxIndex := adoxIndexes.Item[iCount];
sgIndexes.Cells[iCol, iRow] := adoxIndex.Name;
Inc(iCol);
if (adoxIndex.Clustered) then
sgIndexes.Cells[iCol, iRow] := '琌'
else
sgIndexes.Cells[iCol, iRow] := '';
Inc(iCol);
if (adoxIndex.PrimaryKey) then
sgIndexes.Cells[iCol, iRow] := '琌'
else
sgIndexes.Cells[iCol, iRow] := '';
Inc(iCol);
adoxColumns := adoxIndex.Columns;
for iCount1 := 0 to adoxColumns.Count - 1 do // Iterate
begin
adoxColumn := adoxColumns.Item[iCount1];
sgIndexes.Cells[iCol, iRow] := sgIndexes.Cells[iCol, iRow] + ' : ' + adoxColumn.Name;
end; // for
Inc(iRow);
iCol := 0;
end; // for
end;procedure TfrmMain.btnSPClick(Sender: TObject);
var
iCount: Integer;
begin
adoxSPs := adoxCatalog.Procedures;
ClearCells(sgStoredProcs);
iCol := 0;
iRow := 0;
sgStoredProcs.Cells[iCol, iRow] := '箇纗祘嘿';
Inc(iCol);
sgStoredProcs.Cells[iCol, iRow] := 'ミら戳';
Inc(iRow);
for iCount := 0 to adoxSPs.Count - 1 do // Iterate
begin
adoxSP := adoxSPs.Item[iCount];
ShowStoredProceduresInfos;
end; // for
end;procedure TfrmMain.ShowStoredProceduresInfos;
var
iCount: Integer;
begin
iCol := 0;
sgStoredProcs.Cells[iCol, iRow] := adoxSP.Name;
Inc(iCol);
sgStoredProcs.Cells[iCol, iRow] := VarToStr(adoxSP.DateCreated);
Inc(iRow);
end;procedure TfrmMain.btnCreateTableClick(Sender: TObject);
begin
try
frmCreateTable := TfrmCreateTable.Create(Self);
frmCreateTable.SetCatalog(adoxCatalog);
frmCreateTable.SetConnectionString(ADOConnection1.ConnectionString);
frmCreateTable.ShowModal;
finally // wrap up
frmCreateTable.Free;
end; // try/finally
end;procedure TfrmMain.btnDeleteClick(Sender: TObject);
begin
adoxTables := adoxCatalog.Tables;
adoxTables.Delete(lbTables.Items[lbTables.ItemIndex]);
end;end.