/// <summary> /// 更新表结构,返回true表示更新成功! /// </summary> /// <param name="table">Table.</param> /// <typeparam name="T">The 1st type parameter.</typeparam> public bool UpdateTable <T>(table_data_base table) where T : table_data_base { OpenSql(_config.DataBaseIP, _config.DataBaseName, _config.DbUserID, _config.DbPassword, _config.DbPort); var selectOld = SelectList <T> ("id='" + table.id + "'"); if (selectOld == null || selectOld.Count == 0) { return(false); } string setValStr = ""; var oldItem = selectOld [0]; for (int index = 0; index < table.memNameList.Count; index++) { string memberName = table.memNameList [index]; if (oldItem.getMemberValue(memberName) != table.getMemberValue(memberName)) { string valStr = "'" + table.getMemberValue(memberName) + "'"; if (table.getMemberType(memberName).Name == "int") { valStr = table.getMemberValue(memberName) + ""; } setValStr += memberName + "=" + valStr + ","; } } setValStr = setValStr.TrimEnd(','); string newSql = "update " + table.GetType().Name + " set " + setValStr + " where id='" + table.id + "'"; QuerySet(newSql, _config); Close(); return(true); }
/// <summary> /// 从DataSet生成数据表实体对象 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="dataSet"></param> /// <returns></returns> public static List <table_data_base> getListfromDataSet <T>(DataSet dataSet) where T : table_data_base { var list = new List <table_data_base>();// as List<T>;// new table_data_base() as T; for (int index = 0; index < dataSet.Tables[0].Rows.Count; index++) { var tableItem = new table_data_base() as T; if (tableItem.memNameList.Count == 0) { Logger.LogError("类型=" + list.GetType().Name + "的构造函数错误!必须继承自 table_data_base"); return(null); } for (int subIndex = 0; subIndex < tableItem.memNameList.Count; subIndex++) { tableItem.setMemberValue(tableItem.memNameList[subIndex], dataSet.Tables[0].Rows[index][tableItem.memNameList[subIndex]]); } list.Add(tableItem); } return(list); }