例如combobox1中包含水资源名、沙漠名等信息,DBGrid1中显示全部数据库中的信息,我点击水资源名后将数据库中符合的的信息都显示在DBGrid1中,并且不显示不符合的信息unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, DBGrids, DB, ADODB, StdCtrls;type
TForm1 = class(TForm)
ComboBox1: TComboBox;
Button1: TButton;
ADOConnection1: TADOConnection;
ADOTable1: TADOTable;
ADOQuery1: TADOQuery;
DataSource1: TDataSource;
DBGrid1: TDBGrid;
procedure ComboBox1DropDown(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.ComboBox1DropDown(Sender: TObject);
var
i : integer;
begin
ComboBox1.Clear;
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add('Select 统计年份 from qyshjj');
ADOQuery1.Open;
if ADOQuery1.RecordCount>0 then
begin
for i:=0 to ADOQuery1.RecordCount-1 do
begin
ComboBox1.Items.Add(ADOQuery1.FieldByName('统计年份').AsString);
ADOQuery1.Next;
end;
end;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
if Trim(ComboBox1.Text)<>'' then
if ADOTable1.Locate('统计年份',Trim(ComboBox1.Text),[loPartialKey]) then
begin
ADOQuery1.Active := false;
ADOQuery1.SQL.Clear;
if ComboBox1.Text<>'' then
Adoquery1.SQL.Add('select * from qyshjj where 统计年份="'+Combobox1.Text+'"');
Adoquery1.Active := true;
end;
end;
end.
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, DBGrids, DB, ADODB, StdCtrls;type
TForm1 = class(TForm)
ComboBox1: TComboBox;
Button1: TButton;
ADOConnection1: TADOConnection;
ADOTable1: TADOTable;
ADOQuery1: TADOQuery;
DataSource1: TDataSource;
DBGrid1: TDBGrid;
procedure ComboBox1DropDown(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.ComboBox1DropDown(Sender: TObject);
var
i : integer;
begin
ComboBox1.Clear;
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add('Select 统计年份 from qyshjj');
ADOQuery1.Open;
if ADOQuery1.RecordCount>0 then
begin
for i:=0 to ADOQuery1.RecordCount-1 do
begin
ComboBox1.Items.Add(ADOQuery1.FieldByName('统计年份').AsString);
ADOQuery1.Next;
end;
end;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
if Trim(ComboBox1.Text)<>'' then
if ADOTable1.Locate('统计年份',Trim(ComboBox1.Text),[loPartialKey]) then
begin
ADOQuery1.Active := false;
ADOQuery1.SQL.Clear;
if ComboBox1.Text<>'' then
Adoquery1.SQL.Add('select * from qyshjj where 统计年份="'+Combobox1.Text+'"');
Adoquery1.Active := true;
end;
end;
end.
解决方案 »
- delphi用什么方法可以实现异步调用webservice
- 请教LockBox2的RSA加密数据问题
- 急,在文本中怎么样实现重做功能
- 请教一个关于DataSetProvider.ApplyUpdates的问题
- 高手请进:fast report vs acreport(好像是Anycell report)
- 关于TreeView的Hint问题
- 如何使用DBGrid做简单操作,或者用inforpower也行!急急急!今天不解决马上下岗!
- 这是什么原因(ADO)
- 如何获得一个英文字符的区位码?比如‘A’的区位码是‘0701’是怎么得来的?
- 求助,有關一個ClientDataSet問題
- 求一段按字符数量文本分行的代码
- DELPHI中多人编写一套程序!急,在线等
即就是用Filter属性
Filter:= '统计年份 = '''+Trim(ComboBox1.Text)+'''';
设置过滤就可以了
楼主在ComboBox1DropDown事件中给ComboBox1赋了统计年份,怎么又说在【combobox1中包含水资源名、沙漠名等信息】,有点不明白;
查询的时间选择应该用DateTimePicker控件吧;procedure TForm1.ComboBox1Change(Sender: TObject);
begin
if ComboBox1.Text<>'' then begin
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
Adoquery1.SQL.Add('select * from qyshjj where 水资源名='''+Combobox1.Text+''' ');
Adoquery1.SQL.Add('and 统计年份='''+datetostr(DateTimePicker1.Date)+'''');
Adoquery1.Open;
end;
end;