Skip to content

Use with DataRow or DataReader #355

Answered by axunonb
Cirkadia asked this question in Q&A
Discussion options

You must be logged in to vote

DataRow is not a built-in ISource.
Some years ago I came across the same requirement, and actually it's a "one-liner" (probably the same as you found, and I'm not sure whether any better exists):

// convert DataRow to Dictionary<string, object?>
if (dataItem is DataRow row)
{
    dataItem = row.Table.Columns.Cast<DataColumn>().ToDictionary(c => c.ColumnName, c => row[c]);
}

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Cirkadia
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants