/// <summary> /// 得到一个对象实体 /// </summary> public MyBookShop.Model.Settings GetModel(string name) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 Id,Name,Value from Settings "); strSql.Append(" where Name=@name"); SqlParameter[] parameters = { new SqlParameter("@name", SqlDbType.NVarChar,50) }; parameters[0].Value = name; MyBookShop.Model.Settings model = new MyBookShop.Model.Settings(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return DataRowToModel(ds.Tables[0].Rows[0]); } else { return null; } }
/// <summary> /// 得到一个对象实体 /// </summary> public MyBookShop.Model.Settings DataRowToModel(DataRow row) { MyBookShop.Model.Settings model=new MyBookShop.Model.Settings(); if (row != null) { if(row["Id"]!=null && row["Id"].ToString()!="") { model.Id=int.Parse(row["Id"].ToString()); } if(row["Name"]!=null) { model.Name=row["Name"].ToString(); } if(row["Value"]!=null) { model.Value=row["Value"].ToString(); } } return model; }