c# - .RowFilter 与 "IN"和 "NOT IN"

标签 c# sql

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

例子:

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

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

这可能吗?

如果有任何替代方案,请提供帮助。

最佳答案

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

关于c# - .RowFilter 与 "IN"和 "NOT IN",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4068433/

相关文章:

c# - 在多个 HttpWebRequest 中使用相同的 CookieContainer 是否安全?

c# - 获取数组长度

c# - c# 中对象的动态数组(或列表)?

c# - WebApi、iOS 和 Forms Auth - 可以工作吗?

c# - 确保对象不变?

sql - PostgreSQL 强制标准 SQL 语法

php - Add DROP SYNTAX in X-Cloner of Wordpress 是什么意思?

php - MySQL查询无法读取PHP变量

mysql - 从具有 limit 和 desc 的 2 列中获取结果

php - 空和isset检查中的sql注入(inject)漏洞