procedure TForm56.ComboBox1Change(Sender: TObject);
begin
if Trim(ComboBox1.Text)<>''then
begin
with DataModule1.ADOQuery1 do
begin
Close;
SQL.Clear;
SQL.Add('select distinct');
SQL.Add(Trim(ComboBox1.Text));
SQL.Add('from 商品基础信息表');
Open;
end;
ComboBox2.Clear;
while Not DataModule1.ADOQuery1.Eof do
begin
ComboBox2.Items.Add(DataModule1.ADOQuery1.Fields[0].value);
DataModule1 .ADOQuery1.Next;
end;
end;
end;procedure TForm56.SpeedButton1Click(Sender: TObject);
begin
with DataModule1.ADOQuery2 do
begin
Close;
SQL.Clear;
if CheckBox2.Checked = False then
begin
Sql.Text:='select * from 商品基础信息表 where 1=1';
if (ComboBox1.ItemIndex>=0) and (ComboBox2.ItemIndex>=0) then
Sql.Text:=Sql.Text+' and '+Trim(ComboBox1.Text)+'='''+Trim(ComboBox2.Text)+''' ';
if (ComboBox3.ItemIndex>=0) and (ComboBox4.ItemIndex>=0) and (ComboBox7.ItemIndex>=0) then
Sql.Text:=Sql.Text+Trim(ComboBox7.Text)+' '+Trim(ComboBox3.Text)+'='''+Trim(ComboBox4.Text)+''' ';
if (ComboBox5.ItemIndex>=0) and (ComboBox6.ItemIndex>=0) and (ComboBox8.ItemIndex>=0) then
Sql.Text:=Sql.Text+Trim(ComboBox8.Text)+' '+Trim(ComboBox5.Text)+'='''+Trim(ComboBox6.Text)+''' '; end
else
Sql.Text:='select * from 商品基础信息表 where 1=1';
if (ComboBox1.ItemIndex>=0) and (ComboBox2.ItemIndex>=0) then
Sql.Text:=Sql.Text+' and '+Trim(ComboBox1.Text)+'='''+Trim(ComboBox2.Text)+''' ';
if (ComboBox3.ItemIndex>=0) and (ComboBox4.ItemIndex>=0) and (ComboBox7.ItemIndex>=0) then
Sql.Text:=Sql.Text+Trim(ComboBox7.Text)+' '+Trim(ComboBox3.Text)+'='''+Trim(ComboBox4.Text)+''' ';
if (ComboBox5.ItemIndex>=0) and (ComboBox6.ItemIndex>=0) and (ComboBox8.ItemIndex>=0) then
Sql.Text:=Sql.Text+Trim(ComboBox8.Text)+' '+Trim(ComboBox5.Text)+'='''+Trim(ComboBox6.Text)+''' ';
Open;
end;
if DataModule1 .ADOQuery2.RecordCount>0 then
DataSource1.DataSet := DataModule1 .ADOQuery2;
end;
以上语句可正常实现自定义组合条件查询,但把'='''替换成Trim(ComboBox12.text),其中ComboBox12的item属性设置为=、>、<、>=、<=后,查询'开票日期'可正常查询,但是查询'用车单位'后就出现'project delivery.exe raised exception class EOleException with message ‘列名’元德实业’无效.‘. process stopped use step or run to continue.
请高手给予指点。谢谢先!
begin
if Trim(ComboBox1.Text)<>''then
begin
with DataModule1.ADOQuery1 do
begin
Close;
SQL.Clear;
SQL.Add('select distinct');
SQL.Add(Trim(ComboBox1.Text));
SQL.Add('from 商品基础信息表');
Open;
end;
ComboBox2.Clear;
while Not DataModule1.ADOQuery1.Eof do
begin
ComboBox2.Items.Add(DataModule1.ADOQuery1.Fields[0].value);
DataModule1 .ADOQuery1.Next;
end;
end;
end;procedure TForm56.SpeedButton1Click(Sender: TObject);
begin
with DataModule1.ADOQuery2 do
begin
Close;
SQL.Clear;
if CheckBox2.Checked = False then
begin
Sql.Text:='select * from 商品基础信息表 where 1=1';
if (ComboBox1.ItemIndex>=0) and (ComboBox2.ItemIndex>=0) then
Sql.Text:=Sql.Text+' and '+Trim(ComboBox1.Text)+'='''+Trim(ComboBox2.Text)+''' ';
if (ComboBox3.ItemIndex>=0) and (ComboBox4.ItemIndex>=0) and (ComboBox7.ItemIndex>=0) then
Sql.Text:=Sql.Text+Trim(ComboBox7.Text)+' '+Trim(ComboBox3.Text)+'='''+Trim(ComboBox4.Text)+''' ';
if (ComboBox5.ItemIndex>=0) and (ComboBox6.ItemIndex>=0) and (ComboBox8.ItemIndex>=0) then
Sql.Text:=Sql.Text+Trim(ComboBox8.Text)+' '+Trim(ComboBox5.Text)+'='''+Trim(ComboBox6.Text)+''' '; end
else
Sql.Text:='select * from 商品基础信息表 where 1=1';
if (ComboBox1.ItemIndex>=0) and (ComboBox2.ItemIndex>=0) then
Sql.Text:=Sql.Text+' and '+Trim(ComboBox1.Text)+'='''+Trim(ComboBox2.Text)+''' ';
if (ComboBox3.ItemIndex>=0) and (ComboBox4.ItemIndex>=0) and (ComboBox7.ItemIndex>=0) then
Sql.Text:=Sql.Text+Trim(ComboBox7.Text)+' '+Trim(ComboBox3.Text)+'='''+Trim(ComboBox4.Text)+''' ';
if (ComboBox5.ItemIndex>=0) and (ComboBox6.ItemIndex>=0) and (ComboBox8.ItemIndex>=0) then
Sql.Text:=Sql.Text+Trim(ComboBox8.Text)+' '+Trim(ComboBox5.Text)+'='''+Trim(ComboBox6.Text)+''' ';
Open;
end;
if DataModule1 .ADOQuery2.RecordCount>0 then
DataSource1.DataSet := DataModule1 .ADOQuery2;
end;
以上语句可正常实现自定义组合条件查询,但把'='''替换成Trim(ComboBox12.text),其中ComboBox12的item属性设置为=、>、<、>=、<=后,查询'开票日期'可正常查询,但是查询'用车单位'后就出现'project delivery.exe raised exception class EOleException with message ‘列名’元德实业’无效.‘. process stopped use step or run to continue.
请高手给予指点。谢谢先!
解决方案 »
- delphi通过电脑控制蓝牙手机问题!
- 请求指点:如何将TImage中图片写入标准RichEdit控件中?
- 哪能下载<pascal程序设计>这本书
- (二)debussy :请你来领分!
- ontimer事件中的代码,在主进程sleep的时候还运行吗?
- delphi中实现显示出微秒的功能
- 请各位大姥给个水晶报表的delphi开发控件Crystal Report VCL
- 怎么实现一个功能相对强大的对数据库搜索引擎?
- Delphi启动Excel之后就自动关闭了,进程也被关闭
- 还想问一下SQL脚本中GO语句是什么意思啊?
- 李维是不是也进了易博龙?
- fastreport 我使用了memo控件,他的字体来源来源于parentfont:=true;,当运行时候,就只能显示一半字符串了
不过这样的问题很简单应该就可以单步调试找到原因了。
该替换成Trim(ComboBox12.text)+''''
吧?
我建议lz 用QuotedStr()来给字符串加引号。你那么一大堆,怎么看,怎么昏。