实例——应用tadoconnection和tadoquery组件.txt
来自「冒泡排序延时请认真阅读您的文件包然后写出其具体功能(至少要20个字)。尽量不要让」· 文本 代码 · 共 82 行
TXT
82 行
unit U_AdoTable;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Grids, DBGrids, DB, ADODB;
type
TF_AdoTable = class(TForm)
DataSource1: TDataSource;
DBGrid1: TDBGrid;
SaveButton: TButton;
ComboBox1: TComboBox;
ShowButton: TButton;
ADOTable1: TADOTable;
Label1: TLabel;
ADOConnection1: TADOConnection;
procedure SaveButtonClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure ShowButtonClick(Sender: TObject);
private
public
{ Public declarations }
end;
var
F_AdoTable: TF_AdoTable;
DataFileName,BaseFileName: string;
implementation
{$R *.dfm}
procedure TF_AdoTable.FormCreate(Sender: TObject);
var
SL: TStrings;
index: Integer;
begin
Combobox1.Items.Clear;
SL := TStringList.Create;
try
//读取数据库中所包含的数据表的表名
ADOConnection1.GetTableNames(SL, False);
for index := 0 to (SL.Count - 1) do begin
Combobox1.Items.add(SL[index]);
end;
finally
SL.Free;
end;
Combobox1.ItemIndex :=0;
end;
procedure TF_AdoTable.SaveButtonClick(Sender: TObject);
begin
if ADOTable1.Active then
begin
//将记录集中的数据以xml的格式存储到指定文件中
DataFileName := ExtractFilePath(Paramstr(0))+BaseFileName;
ADOTable1.SaveToFile(DataFileName, pfXML);
end
else
MessageDlg('数据表尚未打开,无法存储!', mtInformation,
[mbOk], 0);
end;
procedure TF_AdoTable.ShowButtonClick(Sender: TObject);
begin
self.Caption :=Combobox1.Items[Combobox1.itemindex]+'表';
ADOTable1.Close;
ADOTable1.TableName :=Combobox1.Items[Combobox1.itemindex];
ADOTable1.Open;
//设置保存数据表的文件的名称
BaseFileName := Combobox1.Items[Combobox1.itemindex]+'表'+'.XML';
end;
end.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?