/// <summary> /// 更新一条数据 /// </summary> public bool Update(Cms.Model.C_model model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update C_model set "); strSql.Append("modelName=@modelName,"); strSql.Append("modelValue=@modelValue"); strSql.Append(" where modelId=@modelId"); SqlParameter[] parameters = { new SqlParameter("@modelName", SqlDbType.VarChar, 250), new SqlParameter("@modelValue", SqlDbType.VarChar, 250), new SqlParameter("@modelId", SqlDbType.Int, 4) }; parameters[0].Value = model.modelName; parameters[1].Value = model.modelValue; parameters[2].Value = model.modelId; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Cms.Model.C_model model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into C_model("); strSql.Append("modelName,modelValue)"); strSql.Append(" values ("); strSql.Append("@modelName,@modelValue)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@modelName", SqlDbType.VarChar, 250), new SqlParameter("@modelValue", SqlDbType.VarChar, 250) }; parameters[0].Value = model.modelName; parameters[1].Value = model.modelValue; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Cms.Model.C_model DataRowToModel(DataRow row) { Cms.Model.C_model model = new Cms.Model.C_model(); if (row != null) { if (row["modelId"] != null && row["modelId"].ToString() != "") { model.modelId = int.Parse(row["modelId"].ToString()); } if (row["modelName"] != null) { model.modelName = row["modelName"].ToString(); } if (row["modelValue"] != null) { model.modelValue = row["modelValue"].ToString(); } } return(model); }
/// <summary> /// 得到一个对象实体 /// </summary> public Cms.Model.C_model GetModel(int modelId) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 modelId,modelName,modelValue from C_model "); strSql.Append(" where modelId=@modelId"); SqlParameter[] parameters = { new SqlParameter("@modelId", SqlDbType.Int, 4) }; parameters[0].Value = modelId; Cms.Model.C_model model = new Cms.Model.C_model(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }