/// <summary> /// 更新一条数据 /// </summary> public bool Update(ZhangWei.Model.UserRight model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update UserRight set "); strSql.Append("UserId=@UserId,"); strSql.Append("Rights=@Rights"); strSql.Append(" where "); SqlParameter[] parameters = { new SqlParameter("@UserId", SqlDbType.Int, 4), new SqlParameter("@Rights", SqlDbType.Int, 4) }; parameters[0].Value = model.UserId; parameters[1].Value = model.Rights; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public ZhangWei.Model.UserRight GetModel() { //该表无主键信息,请自定义主键/条件字段 StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 UserId,Rights from UserRight "); strSql.Append(" where "); SqlParameter[] parameters = { }; ZhangWei.Model.UserRight model = new ZhangWei.Model.UserRight(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["UserId"] != null && ds.Tables[0].Rows[0]["UserId"].ToString() != "") { model.UserId = int.Parse(ds.Tables[0].Rows[0]["UserId"].ToString()); } if (ds.Tables[0].Rows[0]["Rights"] != null && ds.Tables[0].Rows[0]["Rights"].ToString() != "") { model.Rights = int.Parse(ds.Tables[0].Rows[0]["Rights"].ToString()); } return(model); } else { return(null); } }
/// <summary> /// 增加一条数据 /// </summary> public void Add(ZhangWei.Model.UserRight model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into UserRight("); strSql.Append("UserId,Rights)"); strSql.Append(" values ("); strSql.Append("@UserId,@Rights)"); SqlParameter[] parameters = { new SqlParameter("@UserId", SqlDbType.Int, 4), new SqlParameter("@Rights", SqlDbType.Int, 4) }; parameters[0].Value = model.UserId; parameters[1].Value = model.Rights; DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); }