开发者

CPP Builder and Ado Filter

I am using C++Builder 2010. I am filtering an ADOTable, in 开发者_JAVA技巧Edit1 OnChange I have:

    ADOTable1->Filter = "firstname like %" + Edit1->Text + "%";

It reports an error when typing in a space, ) and = sign What is the proper way to type the filter? Thanks


I think you need single quotes before and after the string you are passing to the Filter property.

// QuotedStr example
ADOTable1->Filter = "firstname like '%" + QuotedStr(Edit1->Text) + "%'";

// StringReplace example
System::String temp; 
temp = StringReplace(Edit1->Text, "'", "''", TReplaceFlags() << rfReplaceAll);
ADOTable1->Filter = "firstname like '%" + temp + "%'";

The documentation does not mention the LIKE operator, but another website I found suggests this is possible.


I don't have C++ Builder but the below code works on Delphi that is very similar to C++ Builder:

    ADOTable1.filter := 'firstName LIKE '+ QuotedStr('%'+Trim(Edit1.Text)+'%') ;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜