Reputation: 73
I have a datatable which will contain information from various users, the user for each data is stored as a column in my datatable.
How can I extract the relevant data to show in a datagridview only when the user = msalmon and not something like John?
Upvotes: 2
Views: 1257
Reputation: 4883
You can do the following:
private void GetRowsByFilter()
{
DataTable yourDataTable = new DataTable(); //Your DataTable is supposed to have the data
// Presuming the DataTable has a column named user.
string expression;
expression = "user = \"msalmon\"";
DataRow[] foundRows;
// Use the Select method to find all rows matching the filter.
foundRows = table.Select(expression);
// Print column 0 of each returned row.
for(int i = 0; i < foundRows.Length; i ++)
{
Console.WriteLine(foundRows[i][0]);
}
}
Upvotes: 2