佛山网站搜索引擎优化,网站推广的主要方法有哪些,外贸网站建站n,一般做网站用什么软件这个类适用简单的表 1.有且只有id为主键#xff0c; 2.并且实例类主键#xff0c;也就是id应为字段#xff0c;其他为属性 3.实例类名跟表名一样#xff0c;字段属性跟列名一样 public class ProType{public int id;public string type{get;set;}public int array{get;set;…这个类适用简单的表 1.有且只有id为主键 2.并且实例类主键也就是id应为字段其他为属性 3.实例类名跟表名一样字段属性跟列名一样 public class ProType{public int id;public string type{get;set;}public int array{get;set;}public string relyTpye{get;set;}public string etype{get;set;}}下面就是该类的实现 /// summary/// 排序枚举/// /summarypublic enum OrderType { asc, desc }public class SqlDALT where T : new(){private PropertyInfo[] propertys;private Liststring nameList;public SqlDAL(){T t new T();nameList new Liststring();propertys t.GetType().GetProperties();//MessageBox.Show(propertys.Length.ToString());foreach (var item in propertys){nameList.Add(item.Name);}}/// summary/// 查询/// /summary/// returns/returnspublic DataTable Select(){T t new T();string sql select * from t.GetType().Name;DataTable dt new DataTable();dt DBHelper.GetInfo(sql);return dt;}/// summary/// 查询/// /summary/// param nameorderType排序/param/// param namestr排序字段/param/// returns/returnspublic DataTable Select(OrderType orderType, params string[] str){string orderStr ;if (str.Length 0){orderStr order by str[0];for (int i 1; i str.Length; i){orderStr , str[i];}orderStr orderType.ToString();}T t new T();string sql select * from t.GetType().Name orderStr;DataTable dt DBHelper.GetInfo(sql);return dt;}/// summary/// 增/// /summary/// param namet/param/// returns/returnspublic bool Insert(T t){ListSqlParameter parm new ListSqlParameter();foreach (var item in propertys){SqlParameter parmitem new SqlParameter(item.Name, item.GetValue(t, null));parm.Add(parmitem);}string strName ;string strValue ;strName nameList[0];strValue nameList[0];for (int i 1; i nameList.Count; i){strName , nameList[i];strValue , nameList[i];}string sql insert into t.GetType().Name.ToString() ( strName ) values ( strValue );int isAdd DBHelper.Commed(sql, parm.ToArray());if (isAdd 0){return true;}else{return false;}}/// summary/// 改/// /summary/// param namet/param/// returns/returnspublic bool Update(T t){ListSqlParameter parm new ListSqlParameter();foreach (var item in propertys){SqlParameter parmitem new SqlParameter(item.Name, item.GetValue(t, null));parm.Add(parmitem);}string str ;str nameList[0] nameList[0];for (int i 1; i nameList.Count; i){str , nameList[i] nameList[i];}string sql update t.GetType().Name set str where idid;int isUpdate DBHelper.Commed(sql, parm.ToArray());if (isUpdate 0){return true;}else{return false;}}/// summary/// 删/// /summary/// param nameid/param/// returns/returnspublic bool Delete(string id){T t new T();string sql delete from t.GetType().Name where id id;int isDelete DBHelper.Commed(sql);if (isDelete 0){return true;}else{return false;}}} 这里之所以有这个类是因为操作这些表的代码大同小异甚至可以做出通用任意表实例类可以用特征类来标识做出字段与列名的相对应 但那种太过繁琐用来实现这些简单表就有点大材小用所有先弄出了这个类如果后面有机会再实现以下任意表通用类转载于:https://www.cnblogs.com/lsgsanxiao/p/5732339.html