/// <summary> /// 增加一条数据 /// </summary> public bool Add(RolesME model) { StringBuilder strSql=new StringBuilder(); strSql.Append("insert into Roles("); strSql.Append("roleid,rolename,rolevalue)"); strSql.Append(" values ("); strSql.Append("@roleid,@rolename,@rolevalue)"); SqlParameter[] parameters = { new SqlParameter("@roleid", SqlDbType.Int,4), new SqlParameter("@rolename", SqlDbType.NVarChar,50), new SqlParameter("@rolevalue", SqlDbType.VarChar)}; parameters[0].Value = model.roleid; parameters[1].Value = model.rolename; parameters[2].Value = model.rolevalue; int rows = DbHelperSQL.ExecuteSql(PubConstant.ConnectionStringAccountDB,strSql.ToString(), parameters); if (rows > 0) { return true; } else { return false; } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(RolesME model) { StringBuilder strSql=new StringBuilder(); strSql.Append("update Roles set "); strSql.Append("roleid=@roleid,"); strSql.Append("rolevalue=@rolevalue"); strSql.Append(" where rolename=@rolename "); SqlParameter[] parameters = { new SqlParameter("@roleid", SqlDbType.Int,4), new SqlParameter("@rolevalue", SqlDbType.VarChar), new SqlParameter("@rolename", SqlDbType.NVarChar,50)}; parameters[0].Value = model.roleid; parameters[1].Value = model.rolevalue; parameters[2].Value = model.rolename; int rows = DbHelperSQL.ExecuteSql(PubConstant.ConnectionStringAccountDB,strSql.ToString(), parameters); if (rows > 0) { return true; } else { return false; } }
/// <summary> /// 得到一个对象实体 /// </summary> public RolesME GetModel(string rolename) { StringBuilder strSql=new StringBuilder(); strSql.Append("select top 1 roleid,rolename,rolevalue from Roles "); strSql.Append(" where rolename=@rolename "); SqlParameter[] parameters = { new SqlParameter("@rolename", SqlDbType.NVarChar,50) }; parameters[0].Value = rolename; RolesME model=new RolesME(); DataSet ds = DbHelperSQL.Query(PubConstant.ConnectionStringAccountDB,strSql.ToString(), parameters); if(ds.Tables[0].Rows.Count>0) { if(ds.Tables[0].Rows[0]["roleid"]!=null && ds.Tables[0].Rows[0]["roleid"].ToString()!="") { model.roleid=int.Parse(ds.Tables[0].Rows[0]["roleid"].ToString()); } if(ds.Tables[0].Rows[0]["rolename"]!=null && ds.Tables[0].Rows[0]["rolename"].ToString()!="") { model.rolename=ds.Tables[0].Rows[0]["rolename"].ToString(); } if(ds.Tables[0].Rows[0]["rolevalue"]!=null && ds.Tables[0].Rows[0]["rolevalue"].ToString()!="") { model.rolevalue=ds.Tables[0].Rows[0]["rolevalue"].ToString(); } return model; } else { return null; } }