我需要在我的Row端进行过滤,所以如何使用dataview进行设置我需要在datatable中设置仅过滤的记录。 例如:如果我在数据表中有三种类型的记录,我想过滤其中一种,那我该怎么办?
DataView dv = dtsrc.DefaultView; dv.RowFilter ="我应该在这里给出什么样的sintex" ????
答案 0 :(得分:0)
尝试使用DataView.RowFilter
,如下所示:
dv.RowFilter = "Col < 3";
检查此链接: https://msdn.microsoft.com/enus/library/system.data.dataview.rowfilter(v=vs.110).aspx
您还可以使用我推荐的linq
声明:
DataTable orders = dataSet.Tables["SalesOrderHeader"];
EnumerableRowCollection<DataRow> query =
from order in orders.AsEnumerable()
where order.Field<bool>("OnlineOrderFlag") == true
orderby order.Field<decimal>("TotalDue")
select order;
DataView view = query.AsDataView();
bindingSource1.DataSource = view;
点击此链接:https://msdn.microsoft.com/en-us/library/system.data.dataview(v=vs.110).aspx
答案 1 :(得分:-1)
我认为这对你有用 http://www.csharp-examples.net/dataview-rowfilter/
dataView.RowFilter = "Num = 10" // number is equal to 10
dataView.RowFilter = "Date < #1/1/2008#" // date is less than 1/1/2008
dataView.RowFilter = "Name <> 'John'" // string is not equal to 'John'
dataView.RowFilter = "Name >= 'Jo'" // string comparison
答案 2 :(得分:-1)
dv.RowFilter =&#34; Deptno =&#34; + comboBox1.SelectedItem;
您可以从这里参考:
https://www.codeproject.com/Questions/231800/Syntax-of-Rowfilter-in-DataView-In-Csharp