【问题标题】:Excluding null values in DataView在 DataView 中排除空值
【发布时间】:2012-10-15 15:23:14
【问题描述】:

在我的DataTable 的列中是空值。当我在此表上创建 DataView 时,我想过滤掉空值。我该怎么做?

我的代码是这样工作的:

//get the cities and a view on the data
DataTable dtPlaatsen = client.getCities();
DataView dvPlaatsen = dtPlaatsen.DefaultView;

// filter and sort the view
dvPlaatsen.RowFilter= "Isnull(Plaatsnaam,'Null Column') <> 'Null Column'"; 
dvPlaatsen.Sort = "Plaatsnaam";


//attach the view as datasource
ddlCities.DataSource = dvPlaatsen;
ddlCities.DataTextField = "Plaatsnaam"; //the field to display to the user
ddlCities.DataValueField = "PlaatsId"; //the field which is send

ddlCities.DataBind();

ddlCities.SelectedIndex = 50;

【问题讨论】:

    标签: c# filter filtering dataview


    【解决方案1】:

    在排序之前尝试类似的操作,但无论您想做什么过滤器,使用 dataview 行过滤器

              dvPlaatsen.RowFilter = "Plaatsnaam <> null"
    

    【讨论】:

      【解决方案2】:

      试试下面的

      Isnull(Plaatsnaam, 'Null Column') != 'Null Column'
      

      我刚刚修改了来自相关线程 here 的已接受答案。当然,如果它有效,您应该感谢Michael Kjörling 的帮助。

      【讨论】:

        猜你喜欢
        • 2013-06-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-11-13
        • 2014-03-28
        • 2011-05-14
        • 1970-01-01
        相关资源
        最近更新 更多