悬赏园豆:200
[已解决问题]
解决于 2008-01-16 13:44
<P>反射函数:<BR>public void FillModel(object targetObj, DbDataReader reader)<BR> {<BR> Response.Write(reader.GetName(0)); <BR> for (int i = 0; i < reader.FieldCount; i++)<BR> {<BR> System.Reflection.PropertyInfo propertyInfo = targetObj.GetType().GetProperty(reader.GetName(i));<BR> if (propertyInfo != null)<BR> {<BR> System.Web.HttpContext.Current.Response.Write(reader.GetName(i) + ":" + reader[i].ToString() + "<br>");<BR> if (reader.GetValue(i) != DBNull.Value)<BR> {<BR> propertyInfo.SetValue(targetObj, reader.GetValue(i), null);<BR> }<BR> }<BR> }<BR> }</P>
<P> 字段存在,属性已经定义,reader.GetName(0)也可以打印出来属性。<BR>怎么propertyInfo 总是Null亚?</P>