開始寫個啥呢?貼段程式碼留個底吧!
阿新 • • 發佈:2022-03-07
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 else23 { 24 P.SetValue(this, DR[P.Name].ToString(), null); 25 } 26 } 27 } 28 }
本文來自部落格園,作者:隨機的莫代,轉載請註明原文連結:https://www.cnblogs.com/senchal/p/15974868.html