c# - How to use .ToDictionary() extension method on DataRow -


i need dictionary<string,object> produced datarow. have working, doing way , not utilizing .todictionary() extension method.

can please enlighten me on how accomplish successfully?

here failed attempt:

var datadictionary = datatable.select(acn + "=" + accountnumber).todictionary(key => key.table.columns); 

this returns keyvaluepair<datacolumncollection, datarow>, again, need dictionary<string,object>

thanks again in advance!

you need specifiy key want, might acn column in table:

.todictionary(row => (string)row["acn"]); 

todictionary takes second delegate if want run transformation on values in returned dictionary.

edit

i'll leave original answer since explains general case. want take single row; use it's columns keys , column values the, well, values. how that.

 datarow row = datatable.select(acn + "=" + accountnumber).single(); // might want singleordefault  var datadictionary = row.table.columns.todictionary(col => col.name, col => row[col.name]); 

disclaimer, above written without compiler @ hand, might need bit tweaking.


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

sql server - python to mssql encoding problem -

windows - Python Service Installation - "Could not find PythonClass entry" -