.RowFilter,带“IN”和“NOT IN”

时间:2010-11-01 11:25:16

标签: c# sql

将RowFilter应用于DataGridView时遇到问题。我需要将RowFilter应用于INNOT IN

示例:

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

注意:我的网格最初加载了CustMaster表中的所有客户详细信息。我需要的是过滤今天登录的客户的登录详细信息。字段custId也是动态的。

这可能吗?

如果有其他选择请帮助。

2 个答案:

答案 0 :(得分:1)

如何使用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();

答案 1 :(得分:0)

多年前我遇到了一些问题(.net v1),当“IN”使用的表发生变化时,视图不会更新。我不知道这些天问题是否仍然存在于.net框架中。