コード例 #1
0
        /// <summary>
        /// 由主键获取数据
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="tableName"></param>
        /// <param name="key"></param>
        /// <param name="dbid"></param>
        /// <returns></returns>
        public static T GetTModel <T>(string tableName, string key, string dbid)
        {
            T t1 = default(T);

            StringBuilder sb = new StringBuilder();

            sb.AppendFormat(" Select * from {0} ", tableName);
            sb.AppendFormat(" where {0} = '{1}'", key, dbid);
            var ds = DataBaseClass.FullDataSet(sb.ToString());

            if (ds.Tables.Count > 0)
            {
                t1 = PublicTools.ConvertTo <T>(ds.Tables[0]).FirstOrDefault();
                //t1 = (T)Convert.ChangeType(model, t1.GetType());
            }
            //   T t1 = default(T);

            return(t1);
            //return default(T);
        }