再问delphi2006数据库中数据过滤的问题(100分)

  • 主题发起人 主题发起人 hying95
  • 开始时间 开始时间
H

hying95

Unregistered / Unconfirmed
GUEST, unregistred user!
前几天问过同样的问题:
以下代码在D7中没有问题:
procedure TFrmDDLB.ComboBox4Change(Sender: TObject);
begin
with ubde.DM.TbMFLB do
begin
Filtered:=False;
Filter:='类别='+QuotedStr(combobox4.Text);
filtered:=true;
end;
end;
在D2006中会出现以下问题:
Project PDDLB.exe raised exception class EDatabassError with message 'Invalid filter expression character:'类'
hityou回答: '[类别]='+QuotedStr(trim(combobox4.Text));

现在把字段换成变量代码如下
procedure TFrmDDLB.ComboBox4Change(Sender: TObject);
begin
with ubde.DM.TbMFLB do
begin
Filtered:=False;
Filter:=combobox2.text+'='+QuotedStr(combobox4.Text);
filtered:=true;
end;
end;
问题又来了.请高手帮我!(在Delphi2006中解决)
 
假如你Combobox2的items有四个:(名称,代号,类别,颜色)当然可以更多.
可试一试下面的方法.
procedure TFrmDDLB.ComboBox3Change(Sender: TObject);
begin
with ubde.DM.TbMFLB do
begin
Filtered:=False;
if combobox2.Text=combobox2.Items.Strings[0] then
Filter:='[名称]='+QuotedStr(combobox3.Text);
if combobox2.Text=combobox2.Items.Strings[1] then
Filter:='[代号]='+QuotedStr(combobox3.Text);
if combobox2.Text=combobox2.Items.Strings[2] then
Filter:='[类别]='+QuotedStr(combobox3.Text);
if combobox2.Text=combobox2.Items.Strings[3] then
Filter:='[颜色]='+QuotedStr(combobox3.Text);
filtered:=true;
end;
end;
 
Filter:=Format('[%s]=%s', [combobox2.text, QuotedStr(combobox4.Text)]);
 
SP229的方法可以通过但有点麻烦.
dreamisx的方法可通过编译,但是执行Combobox4Change事件后,DBGrid中什么都没有了,记录全过滤了.
 
刚才我搞错了,dreamisx的方法可以,谢谢了.
同时也谢谢SP229.
 
多人接受答案了。
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
917
SUNSTONE的Delphi笔记
S
S
回复
0
查看
898
SUNSTONE的Delphi笔记
S
S
回复
0
查看
1K
SUNSTONE的Delphi笔记
S
后退
顶部