将dataReader转换为Dictionary [英] convert dataReader to Dictionary

查看:110
本文介绍了将dataReader转换为Dictionary的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用LINQ将一行转换为字典(fieldName - > fieldValue)

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

但我收到错误消息:



实例参数:不能从'System.Collections.Generic.IEnumerable< int>'转换为'System.Collections.Generic.IEnumerable< string>'



如何纠正?

解决方案

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


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?

解决方案

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

这篇关于将dataReader转换为Dictionary的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆