You can simply use SQL query statements to retrieve desired data from database server with C# and ADO.Net. But there are plenty of ways to search your localized version of data which is stored in dataSet and dataView.
We already learn how to use Find and Findrow methods for searching data in Visual Studio App. This post will show how to use row filter property of DataView for sorting data rows.
- First up all you need to create Data adaptor, dataSet, and dataView.
- In our example, I have a date field in the database table, so that I can filter for specific date ranges as follows
Common.AccountReportDV.RowFilter = "invoicedate>='" + dateTimePicker1.Value.ToShortDateString() + "' and invoicedate<='" + dateTimePicker2.Value.ToShortDateString() + "'";
Here common is a public static class where kept the Database functions. The above statement will be looking for data between the two dates.
You have to use Common.AccountReportDV and not Common.AccountReportDV.Table.rows for retrieving the result as follows.
foreach (DataRowView row in Common.AccountReportDV) { console.WriteLine(row["<column name here>"]); }
DataRowView is a special class which helps to access data rows in a DataView object.
One thought on “How to use dataView rowfilter for searching rows in C#.Net”