开发者

.RowFilter with "IN" and "NOT IN"

I have a issue with applying a RowFilter to a DataGridView. I do need to apply RowFilter with IN and NOT IN.

Example:

custId in (select custId from loginDetails where date = '01/11/2010')

Note: My grid is initially loaded with all customer details from CustMaster table. what I need is to filter login details of a 开发者_JAVA技巧customer who logged on today. Field custId is also dynamic.

Will this be possible ?

If any alternative please help.


How about using LINQ?

//1. Pick all of those that you do not want in your code.
//2. Select those that you want.
var result = from record in dtLoginDetails.AsEnumerable()
                where //2. Select all records.
                (!( //Remove the ! sign to use IN/NOT IN
                (from custID in dtLoginDetails.AsEnumerable()
                    where custID.Field<string>("author").StartsWith("C") //1. Select those records that are unwanted.
                    //Note that, in your case you can add it like 
                    //unwanted.Field<DateTime>("Date") = DateTime.Now.Date
                select custID.Field<string>("author") 
                )
                .Contains(record.Field<string>("author"))
                )

                )
                select record;

//Cast as DataView
DataView view = result.AsDataView();


I had problems many years ago (.net v1) with views not updating when the tables used by the "IN" changed. I don't know if the problem is still in the .net framework these days.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜