开发者

CPP Builder and Ado Filter

开发者 https://www.devze.com 2023-03-16 02:59 出处:网络
I am using C++Builder 2010. I am filtering an ADOTable, in 开发者_JAVA技巧Edit1 OnChange I have:

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

精彩评论

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