0

I need filter in my Row side so how to set using dataview i need set only filtered record in datatable . Ex : if i have three types of record available in datatable and i want to filter one of them so what should i do??

DataView dv = dtsrc.DefaultView; dv.RowFilter = "what's the sintex should i give here" ????

1
  • Guys I have Found Solution For that like Following .... And its Working properly DataView dv = dtsrc.DefaultView; dv.RowFilter = "[TransactionType] LIKE '%" + TransactionType + "%'"; DataTable dtNew = dv.ToTable(); My_DataTable = dtNew; We can Get Filtered Data in to My_DataTable! Commented Mar 24, 2017 at 10:24

3 Answers 3

0

Try using DataView.RowFilter like this :

dv.RowFilter = "Col < 3";

Check this link : https://msdn.microsoft.com/enus/library/system.data.dataview.rowfilter(v=vs.110).aspx

You can also use linq statement which I recommend :

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;

Check this link : https://msdn.microsoft.com/en-us/library/system.data.dataview(v=vs.110).aspx

Sign up to request clarification or add additional context in comments.

Comments

-1

I think this is usefull for you 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

1 Comment

Dude I have Found Solution For that like Following .... And its Working properly . DataView dv = dtsrc.DefaultView; dv.RowFilter = "[TransactionType] LIKE '%" + TransactionType + "%'"; DataTable dtNew = dv.ToTable(); My_DataTable = dtNew; We can Get Filtered Data in to My_DataTable!
-2

dv.RowFilter = "Deptno=" + comboBox1.SelectedItem;

You may take reference from here:

https://www.codeproject.com/Questions/231800/Syntax-of-Rowfilter-in-DataView-In-Csharp

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.