convert dataReader to Dictionary

时间秒杀一切 提交于 2019-12-22 07:37:23

问题


I tried to use LINQ to convert one row to Dictionary (fieldName -> fieldValue)

return Enumerable.Range(0, reader.FieldCount)
                 .ToDictionary<string, object>(reader.GetName, reader.GetValue);

but I received error message:

Instance argument: cannot convert from 'System.Collections.Generic.IEnumerable<int>' to 'System.Collections.Generic.IEnumerable<string>'

How to correct this?


回答1:


return Enumerable.Range(0, reader.FieldCount)
                 .ToDictionary(
                     i => reader.GetName(i),
                     i => reader.GetValue(i));


来源:https://stackoverflow.com/questions/11842651/convert-datareader-to-dictionary

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!