public static T GetObject <T>(DataRow dr) where T : new() { T list = new T(); list = TableList <T> .ConvertModel(dr); return(list); }
/// <summary> /// 由表得到集合 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="dt"></param> /// <returns></returns> public List <T> FillCollection <T>(DataTable dt) where T : new() { List <T> list = new List <T>(); list = TableList <T> .TableToList(dt, false); return(list); }
/// <summary> /// sql语句得到集合 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="cmd"></param> /// <returns></returns> public List <T> FillCollection <T>(string cmd) where T : new() { List <T> list = new List <T>(); DataSet ds = this.Getds(cmd, "temp"); list = TableList <T> .TableToList(ds.Tables["temp"], false); return(list); }
/// <summary> /// /// </summary> /// <typeparam name="T"></typeparam> /// <param name="cmd"></param> /// <returns></returns> public T FillT <T>(string cmd) where T : new() { T list = new T(); DataSet ds = this.Getds(cmd, "temp"); if (ds.Tables["temp"].Rows.Count > 0) { list = TableList <T> .ConvertModel(ds.Tables["temp"].Rows[0]); } return(list); }
/// <summary> /// 支持更改和插入操作,不支持删除操作。 行(如果已经存在一行的话)或者添加行(如果尚且不存在行的话)时,LoadDataRow 最有用。如果找到了行的键值,LoadDataRow 将更新该行的值,而不是插入新行。 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="list"></param> /// <param name="dt"></param> /// <param name="tableName"></param> public void UpdateList <T>(List <T> list, ref DataTable dt, string tableName) where T : new() { //DataTable dtnew= TableList<T>.ToDataTable<T>(list); ////比较2个表 产生一个结果 //foreach (DataRow dr in dtnew.Rows) //{ // dr. // if (dt.Rows.Contains(dr)) // { // } //} TableList <T> .ToDataTable <T>(list, ref dt); string str = "select * from " + tableName; this.UpdateDs(dt, str); }