我用ADO控件连接access数据库啊,想在ListView里面显示出来。以下是代码。
procedure TForm1.FormCreate(Sender: TObject);
begin
mypath:=extractfilepath(paramstr(0));
shortdateformat:='yyyy/mm/dd';
end;procedure TForm1.RadioButton1Click(Sender: TObject);
begin
edit1.Text :='';
end;procedure TForm1.RadioButton2Click(Sender: TObject);
begin
edit1.Text :='';
end;procedure TForm1.RadioButton3Click(Sender: TObject);
begin
edit1.Text :='';
end;procedure TForm1.RadioButton4Click(Sender: TObject);
begin
edit1.Text :='';
end;procedure TForm1.Button1Click(Sender: TObject);
var
content:string;begin
try
listview1.Items.Clear ;
begin
with DataModule2.ADOQuery1 do
begin
content:=edit1.Text ;
if ComboBox1.ItemIndex=-1 then
content:='%'+content+'%';
sql.Clear ;
if radiobutton1.Checked then
begin
sql.Add('select BZM,ZH,YFLH,ZWM from w where code like :BZM ');
parameters.ParamByName('BZM').Value :=content;
end;
if radiobutton2.Checked then
begin
sql.Add('select BZM,ZH,YFLH,ZWM from w where name like :ZM ');
parameters.ParamByName('ZM').Value :=content;
end;
if radiobutton3.Checked then
begin
sql.Add('select BZM,ZH,YFLH,ZWM from w where YFLH like :YFLH ');
parameters.ParamByName('YFLH').Value :=content;
end;
if radiobutton4.Checked then
begin
sql.Add('select BZM,ZH,YFLH,ZWM from w where ZWM like :ZWM ');
parameters.ParamByName('ZWM').Value :=content;
end;
open;
while not eof do
begin
with listview1.Items.Add do
begin
caption:=fieldbyname('BZM').AsString ;
subitems.add(fieldbyname('ZH').AsString );
subitems.add(fieldbyname('YFLH').AsString );
subitems.add(fieldbyname('ZWM').AsString );
end;
next;
end; end; end;
except
messagedlg('查询失败',mterror,[mbok],0); end;
end;end.
procedure TForm1.FormCreate(Sender: TObject);
begin
mypath:=extractfilepath(paramstr(0));
shortdateformat:='yyyy/mm/dd';
end;procedure TForm1.RadioButton1Click(Sender: TObject);
begin
edit1.Text :='';
end;procedure TForm1.RadioButton2Click(Sender: TObject);
begin
edit1.Text :='';
end;procedure TForm1.RadioButton3Click(Sender: TObject);
begin
edit1.Text :='';
end;procedure TForm1.RadioButton4Click(Sender: TObject);
begin
edit1.Text :='';
end;procedure TForm1.Button1Click(Sender: TObject);
var
content:string;begin
try
listview1.Items.Clear ;
begin
with DataModule2.ADOQuery1 do
begin
content:=edit1.Text ;
if ComboBox1.ItemIndex=-1 then
content:='%'+content+'%';
sql.Clear ;
if radiobutton1.Checked then
begin
sql.Add('select BZM,ZH,YFLH,ZWM from w where code like :BZM ');
parameters.ParamByName('BZM').Value :=content;
end;
if radiobutton2.Checked then
begin
sql.Add('select BZM,ZH,YFLH,ZWM from w where name like :ZM ');
parameters.ParamByName('ZM').Value :=content;
end;
if radiobutton3.Checked then
begin
sql.Add('select BZM,ZH,YFLH,ZWM from w where YFLH like :YFLH ');
parameters.ParamByName('YFLH').Value :=content;
end;
if radiobutton4.Checked then
begin
sql.Add('select BZM,ZH,YFLH,ZWM from w where ZWM like :ZWM ');
parameters.ParamByName('ZWM').Value :=content;
end;
open;
while not eof do
begin
with listview1.Items.Add do
begin
caption:=fieldbyname('BZM').AsString ;
subitems.add(fieldbyname('ZH').AsString );
subitems.add(fieldbyname('YFLH').AsString );
subitems.add(fieldbyname('ZWM').AsString );
end;
next;
end; end; end;
except
messagedlg('查询失败',mterror,[mbok],0); end;
end;end.
解决方案 »
- 请教如何防止ACCESS的数据自动恢复
- Embarcadero公布RAD Studio Roadmap! 2010-5-10更新
- 为何我没有这个函数的帮助提示?
- 小伍哥也有宝宝了, delphi 版的已婚男大都当爸爸了吧。。
- 我的Dephi 7 ide中没有midas页,该怎么办......? 在线
- 怎样在DBGrid的某个单元格中加一个小按钮?
- 请问一个关于时间查询的简单问题。
- 难道这个问题很复杂吗?真没高手吗
- 生成按钮,单击事件释放问题 ,求解
- 楼下的兄弟我经常干14----15个小时,偶尔还上通宵。
- 急:外包一个数据库管理软件的活,有意向的朋友请进来看看。
- 项目管理人员和想做项目管理的人,快出招!!!!
sql.text:='';
当然会提示SQL语句没有了。