开始写个啥呢?贴段代码留个底吧!
1 /// <summary> 2 /// 根据ID读取一条数据,并赋值给所有属性 3 /// 需要初始化ID参数 4 /// </summary> 5 public void getValueFromId(dataSelect Dselect) 6 { 7 string sql = "select * from " + tabName + " where id=" + id; 8 DataTable DTab = Dselect.select_tab(sql); 9 foreach (DataRow DR in DTab.Rows) 10 { 11 PropertyInfo[] PP = this.GetType().GetProperties(); 12 foreach (PropertyInfo P in PP) 13 { 14 if (P.PropertyType.Name == "Int32") 15 { 16 P.SetValue(this, funMath.toMathInt(DR[P.Name].ToString()), null); 17 } 18 else if (P.PropertyType.Name == "DateTime") 19 { 20 P.SetValue(this, funTime.strToTime(DR[P.Name].ToString()), null); 21 } 22 else 23 { 24 P.SetValue(this, DR[P.Name].ToString(), null); 25 } 26 } 27 } 28 }
本文来自博客园,作者:随机的莫代,转载请注明原文链接:https://www.cnblogs.com/senchal/p/15974868.html