2010-11-01 96 views
2

我在將RowFilter應用於DataGridView時遇到了問題。我確實需要應用RowFilter INNOT IN。使用「IN」和「NOT IN」的RowFilter

例子:

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

注:我的網最初加載來自CustMaster表中的所有客戶的詳細信息。我需要的是過濾今天登錄的客戶的登錄細節。字段custId也是動態的。

這可能嗎?

如果有其他方法請幫忙。

+0

當你應用rowfilter =「custId(從loginDetails where date = '01/11/2010')」時,實際發生了什麼? – smirkingman 2010-11-01 11:57:09

回答

0

多年前我遇到了問題(.net v1),當「IN」使用的表發生變化時,視圖不會更新。我不知道這些問題是否仍然在.net框架中。

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