前两篇博文我们提了好多的ADO,我们下面来看一下Delphi在ADO方面的强大之处!
-------------------------------------------------------------------------------------------------美丽分割线---------------------------
效果如下图:
此程序使用ADOConnection、ADODataSet、DataSource、DBGrid等控件完成一个简单的数据库(MS Access)操作(添、删、改、查)。
在使用ADOConnection时,注意把LoginPrompt设置为False!
单元文件:
Unit1.pas
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Grids, DBGrids, ExtCtrls, DBCtrls, DB, ADODB, StdCtrls; type TForm1 = class(TForm) Panel1: TPanel; Panel2: TPanel; Button3: TButton; Button4: TButton; DBNavigator1: TDBNavigator; Button5: TButton; Button6: TButton; Button7: TButton; Button9: TButton; Button8: TButton; Button12: TButton; Button11: TButton; Button10: TButton; Button1: TButton; Edit1: TEdit; Label1: TLabel; DataSource1: TDataSource; DBGrid1: TDBGrid; ADOConnection1: TADOConnection; ADODataSet1: TADODataSet; procedure Button1Click(Sender: TObject); procedure Button3Click(Sender: TObject); procedure Button4Click(Sender: TObject); procedure Button5Click(Sender: TObject); procedure Button6Click(Sender: TObject); procedure Button7Click(Sender: TObject); procedure Button9Click(Sender: TObject); procedure Button8Click(Sender: TObject); procedure Button10Click(Sender: TObject); procedure Button11Click(Sender: TObject); procedure Button12Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); begin ADODataSet1.Close; if Trim(Edit1.Text) <> '' then ADODataSet1.CommandText:='select * from 表1 where 货名='+''''+Edit1.Text+'''' else ADODataSet1.CommandText:='select * from 表1'; ADODataSet1.Open; end; procedure TForm1.Button3Click(Sender: TObject); begin DBNavigator1.BtnClick(nbFirst); end; procedure TForm1.Button4Click(Sender: TObject); begin DBNavigator1.BtnClick(nbPrior); end; procedure TForm1.Button5Click(Sender: TObject); begin DBNavigator1.BtnClick(nbNext); end; procedure TForm1.Button6Click(Sender: TObject); begin DBNavigator1.BtnClick(nbLast); end; procedure TForm1.Button7Click(Sender: TObject); begin DBNavigator1.BtnClick(nbInsert); end; procedure TForm1.Button9Click(Sender: TObject); begin DBNavigator1.BtnClick(nbDelete); end; procedure TForm1.Button8Click(Sender: TObject); begin DBNavigator1.BtnClick(nbEdit); end; procedure TForm1.Button10Click(Sender: TObject); begin DBNavigator1.BtnClick(nbPost); end; procedure TForm1.Button11Click(Sender: TObject); begin DBNavigator1.BtnClick(nbCancel); end; procedure TForm1.Button12Click(Sender: TObject); begin DBNavigator1.BtnClick(nbRefresh); end; end.
文件:lqx.7z
==========如果文件有密码:tdtc_hrb#163.com========把井号替换为at符号即可======
作者:xiaobin_HLJ80 发表于2013-5-20 0:40:37 原文链接
阅读:115 评论:0 查看评论