初学delphi,我用一个ComboBox1,Edit1,跟dbgrid实现查询功能,用户在在ComboBox1里面选择查询字段,在edit1里面编辑查询内容,在查询过程里面我写了如下代码,可是在dbgrid里面什么也没返回,请帮我改正,如果有更好的方法,请赐教!
procedure Tkkkkk.BitBtn5Click(Sender: TObject);
var chose1, key, chose2: string;
begin
chose1 := trim(ComboBox1.Text);
key := trim(Edit1.Text);
if chose1 = '名称' then
chose2 := 'name'
else if chose1 = '负责人' then
chose2 := 'contractor'
else if chose1 = '类型' then
chose2 := 'sign'
else
ShowMessage('错误的搜索类型!');with DataMa_ADOQueryloft do
begin
DataMa_ADOQueryloft.Close;
DataMa_ADOQueryloft.SQL.Clear;
DataMa_ADOQueryloft.SQL.Add('Select * From Jobarea Where '''+chose2+''' = '''+key+'''' );
DataMa_ADOQueryloft.Open;
procedure Tkkkkk.BitBtn5Click(Sender: TObject);
var chose1, key, chose2: string;
begin
chose1 := trim(ComboBox1.Text);
key := trim(Edit1.Text);
if chose1 = '名称' then
chose2 := 'name'
else if chose1 = '负责人' then
chose2 := 'contractor'
else if chose1 = '类型' then
chose2 := 'sign'
else
ShowMessage('错误的搜索类型!');with DataMa_ADOQueryloft do
begin
DataMa_ADOQueryloft.Close;
DataMa_ADOQueryloft.SQL.Clear;
DataMa_ADOQueryloft.SQL.Add('Select * From Jobarea Where '''+chose2+''' = '''+key+'''' );
DataMa_ADOQueryloft.Open;
begin
DataMa_ADOQueryloft.Close;
DataMa_ADOQueryloft.SQL.Clear;
DataMa_ADOQueryloft.SQL.Add('Select * From Jobarea Where '+chose2+' = '''+key+'''' );
DataMa_ADOQueryloft.Open;
end;DateSource连了DbGrid了么
DataMa_ADOQueryloft.SQL.Clear;
DataMa_ADOQueryloft.SQL.Add('Select * From Jobarea Where '''+chose2+''' = '''+key+'''' );
DataMa_ADOQueryloft.Open;
应该改为
DataMa_ADOQueryloft.SQL.Add('Select * From Jobarea Where '+chose2+' = '''+key+'''' );