I use a DataTable with Information about Users and I want search a user or a list of users in this DataTable. I try it butit don't work :(
Here is my c# code:
public DataTable GetEntriesBySearch(string username,string location,DataTable table) { list = null; list = table; string expression; string sortOrder; expression = "Nachname = 'test'"; sortOrder = "nachname DESC"; DataRow[] rows = list.Select(expression, sortOrder); list = null; // for testing list = new DataTable(); // for testing foreach (DataRow row in rows) { list.ImportRow(row); } return list; }
After a DataView has been created from a DataTable or LINQ to DataSet query, you can use the RowFilter property to specify subsets of rows based on their column values. The string-based and expression-based filters are mutually exclusive.
First solution, once you click on drop down search box will filled with what you selected and populate the result but you can always see search box with selected value. var selectedValue=$("#month-select"). val(); table. columns(6).search( selectedValue ).
Using select method is the best approach to filter data from a data table based on a condition. Explanation: The 'SQL select statement' is used for returning the result of set of records from the given one or more tables of a provided database.
You can use DataView.
DataView dv = new DataView(yourDatatable); dv.RowFilter = "query"; // query example = "id = 10"
http://www.csharp-examples.net/dataview-rowfilter/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With