I'd like to use LINQ to take a datarow, and parse out the datacolumn names with their values.
So if I had a dataRow with the following columns and values:
DataColumn column1 with value '1'
DataColumn column2 with value 'ABC'
I'd like to have a string returned as "column1 = '1' and column2 = 'ABC'"
**** code should not care about the column names, nor the number of columns in the table.****
Purpose being, to filter a dataTable like:
var newRows = myTable.Select ("column1 = '1' and column2 = 'ABC'");
I can parse out the columns of the table like this:
string[] columnName = myTable.Columns.Cast<DataColumn>().Select(cn => cn.ColumnName).ToArray();
But I need to also extract values from a target row. It feels like this might be a start:
{
string[] columnNames = existingTable.Columns.Cast<DataColumn>().Select(cn => cn.ColumnName).ToArray();
foreach (DataRow oldRow in existingTable.Rows)
{
var criteria = string.Join("and", columnNames, oldRow.ItemArray);
}
}