/// <summary> /// 得到一个对象实体 /// </summary> public ChouJiangClassModel GetModel(int ChouJiangClassId) { StringBuilder strSql = new StringBuilder(); strSql.Append("select ChouJiangClassId, ChouJiangClassName, ChouJiangMemo "); strSql.Append(" from YYHD.dbo.ChouJiangClass "); strSql.Append(" where ChouJiangClassId=@ChouJiangClassId"); SqlParameter[] parameters = { new SqlParameter("@ChouJiangClassId", SqlDbType.Int, 4) }; parameters[0].Value = ChouJiangClassId; ChouJiangClassModel model = new ChouJiangClassModel(); DataSet ds = helper.ExecSqlReDs(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["ChouJiangClassId"].ToString() != "") { model.ChouJiangClassId = int.Parse(ds.Tables[0].Rows[0]["ChouJiangClassId"].ToString()); } model.ChouJiangClassName = ds.Tables[0].Rows[0]["ChouJiangClassName"].ToString(); model.ChouJiangMemo = ds.Tables[0].Rows[0]["ChouJiangMemo"].ToString(); return(model); } else { return(model); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(ChouJiangClassModel model) { bool reValue = true; int reCount = 0; StringBuilder strSql = new StringBuilder(); strSql.Append("update YYHD.dbo.ChouJiangClass set "); strSql.Append(" ChouJiangClassName = @ChouJiangClassName , "); strSql.Append(" ChouJiangMemo = @ChouJiangMemo "); strSql.Append(" where ChouJiangClassId=@ChouJiangClassId "); SqlParameter[] parameters = { new SqlParameter("@ChouJiangClassId", SqlDbType.Int, 4), new SqlParameter("@ChouJiangClassName", SqlDbType.VarChar, 50), new SqlParameter("@ChouJiangMemo", SqlDbType.VarChar, 500) }; parameters[0].Value = model.ChouJiangClassId; parameters[1].Value = model.ChouJiangClassName; parameters[2].Value = model.ChouJiangMemo; try {//异常处理 reCount = this.helper.ExecSqlReInt(strSql.ToString(), parameters); } catch (Exception ex) { this.helper.Close(); throw ex; } if (reCount <= 0) { reValue = false; } return(reValue); }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(ChouJiangClassModel model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into YYHD.dbo.ChouJiangClass ("); strSql.Append("ChouJiangClassName,ChouJiangMemo"); strSql.Append(") values ("); strSql.Append("@ChouJiangClassName,@ChouJiangMemo"); strSql.Append(") "); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@ChouJiangClassName", SqlDbType.VarChar, 50), new SqlParameter("@ChouJiangMemo", SqlDbType.VarChar, 500) }; parameters[0].Value = model.ChouJiangClassName; parameters[1].Value = model.ChouJiangMemo; bool result = false; try { helper.ExecSqlReInt(strSql.ToString(), parameters); result = true; } catch (Exception ex) { this.helper.Close(); throw ex; } finally { } return(result); }