/// <summary>
/// method for updating the users information
/// </summary>
/// <returns></returns>
public bool UpdateAdminUser()
{
try
{
//int to hold the # of rows affected
int rows = 0;
//string to hold the stored procedure we're executing
string query = "uspUpdateAdminUser";
//create a SqlConnection and open it
using (SqlConnection conn = new SqlConnection(QmetroDBHelper.GetConnectionString("Qmetro")))
{
//create a SqlCommand instance
SqlCommand cmd = new SqlCommand();
//set the commands properties
cmd.CommandText = query;
cmd.CommandType = CommandType.StoredProcedure;
//add the stored procedure properties
cmd.Parameters.AddWithValue("@intAdminUserID_PK", _userID);
cmd.Parameters.AddWithValue("@chrAccessLevel", _accessLevel);
cmd.Parameters.AddWithValue("@chrName", _name);
cmd.Parameters.AddWithValue("@chrEmail", _email);
//now see if the user changed the password
if (!(string.IsNullOrEmpty(_password)))
{
//they provided a password so we need to update that and their salt value
cmd.Parameters.AddWithValue("@chrPassword", HashPassword(_password));
cmd.Parameters.AddWithValue("@chrPasswordSalt", _saltValue);
}
else
{
//no password, pass null
cmd.Parameters.AddWithValue("@chrPassword", DBNull.Value);
cmd.Parameters.AddWithValue("@chrPasswordSalt", DBNull.Value);
}
cmd.Parameters.AddWithValue("@blnIsActive", _isActive);
cmd.Parameters.AddWithValue("@blnAccountLocked", _isLocked);
//set it's connection property
cmd.Connection = conn;
//open our connection
conn.Open();
//now execute
rows = cmd.ExecuteNonQuery();
//close our connection
conn.Close();
//clean up
conn.Dispose();
cmd.Dispose();
//check the value
if (!(rows > 0))
{
return false;
}
else
{
return true;
}
}
}
catch (SqlException ex)
{
_returnMessage = ex.Message;
return false;
}
catch (Exception ex)
{
_returnMessage = ex.Message;
return false;
}
}
I call this method in a button click
protected void cmdEditUser_Click(object sender, EventArgs e)
{
//create an Admin object
QmetroAdmin admin = new QmetroAdmin();
//set our properties
admin.FullName = edituser_fullname.Text;
admin.Email = edituser_email.Text;
admin.AccessLevel = GetSelectedSections(edituser_accessto);
admin.IsActive = Convert.ToInt32(edituser_active.SelectedItem.Value);
admin.IsLocked = Convert.ToInt32(edituser_locked.SelectedItem.Value);
admin.Password = edituser_password.Text;
admin.AdminUserID = Convert.ToInt32(Request.QueryString["id"]);
//now we update and check the status
if (!(admin.UpdateAdminUser()))
{
EditErrorMessage.Text = admin.ReturnMessage;
//Response.Redirect("Users.aspx?action=view");
}
else
{
Response.Redirect("Users.aspx?action=view");
}
}
The stored procedure works because Ive ran it in Query Analyzer with no problems. With this it is returning true but isn't updating the users information. Anyone see anything wrong? Doesn't it suck that it's generally something you've done a thousand times that ends up giving you problems

New Topic/Question
Reply



MultiQuote






|