能,但要用TQUERY
SQL语句你会吧,那就行了
BYE
SQL语句你会吧,那就行了
BYE
解决方案 »
- 程序设置代理服务器,下面的代码为什么不起作用?
- 比较简单的问题
- 我写的一个程序快完成了,delphi7+ado+sql server2000+fastreport,我想变成局域网版,请问要如何操作。
- 请教一个问题?????????????????来者有分
- 怎么安装QReport控件?
- 请教一个从串口读数据的问题,很简单
- 聘delphi+sqlServer , 实际工作经验一年以上。学历无要求。年龄无要求。
- 关于SQL日期的几个小问题,分数全给第一个解决问题的朋友。
- 关于用ADO控件连接数据库的跨数据库问题?
- 大侠们请进:delphi中打开一个word文档问题
- 个人仿制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.