I can’t figure out why this isn’t working?!
protected void Submit_Click(object sender, EventArgs e)
{
Update();
}
public void Update()
{
try
{
using (SqlConnection conn =
new SqlConnection(conStr))
{
conn.Open();
using (SqlCommand cmd =
new SqlCommand("UPDATE DriverInfo SET FirstName=@NewFirstName, LastName=@NewLastName, Age=@NewAge, Country=@NewCountry, Town=@NewTown WHERE UserId=@Id", conn))
{
cmd.Parameters.AddWithValue("@Id", currentUserId);
cmd.Parameters.AddWithValue("@NewFirstName", tbfirstname.Text);
cmd.Parameters.AddWithValue("@NewLastName", tblastname.Text);
cmd.Parameters.AddWithValue("@NewAge", tbage.Text);
cmd.Parameters.AddWithValue("@NewCountry", tbcountry.Text);
cmd.Parameters.AddWithValue("@NewTown", tbtown.Text);
int rows = cmd.ExecuteNonQuery();
//rows number of record got updated
}
}
}
catch (SqlException ex)
{
//Log exception
//Display Error message
}
}
This should be a page where the logged in user can change his settings and them should be updated in the database.
The only thing that I can see from the code given and with no exceptions is that the
@Idmay not be set right or not be equal to any existing Id’s in the current table.