我将数据表与有关用户的信息一起使用,并且我想在此数据表中搜索一个用户或用户列表。我尝试了,但是不起作用:(
这是我的C#代码:
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; }
您可以使用DataView。
DataView dv = new DataView(yourDatatable); dv.RowFilter = "query"; // query example = "id = 10"
http://www.csharp-examples.net/dataview-rowfilter/