DataReader 数据流转为Dynamic对象。
时间:2010-11-08 来源:祝金峰
1 /// <summary>
2 /// 将DataReader数据转为Dynamic对象
3 /// </summary>
4 /// <param name="reader"></param>
5 /// <returns></returns>
6 public static dynamic DataFillDynamic(IDataReader reader)
7 {
8 dynamic d = new ExpandoObject();
9 for (int i = 0; i < reader.FieldCount; i++)
10 {
11 try
12 {
13 ((IDictionary<string, object>)d).Add(reader.GetName(i), reader.GetValue(i));
14 }
15 catch
16 {
17 ((IDictionary<string, object>)d).Add(reader.GetName(i), null);
18 }
19 }
20 return d;
21 }
22
2 /// 将DataReader数据转为Dynamic对象
3 /// </summary>
4 /// <param name="reader"></param>
5 /// <returns></returns>
6 public static dynamic DataFillDynamic(IDataReader reader)
7 {
8 dynamic d = new ExpandoObject();
9 for (int i = 0; i < reader.FieldCount; i++)
10 {
11 try
12 {
13 ((IDictionary<string, object>)d).Add(reader.GetName(i), reader.GetValue(i));
14 }
15 catch
16 {
17 ((IDictionary<string, object>)d).Add(reader.GetName(i), null);
18 }
19 }
20 return d;
21 }
22
相关阅读 更多 +