Thursday, October 3, 2013

My table is not updating

Hi


Please try this code



string connString = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;

SqlConnection conn = new SqlConnection(connString);


string updateCommand = "update [Users] set FirstNameLastName=@FirstNameLastname," +
" Gender=@Gender," +
" PlaceOfBirth=@PlaceOfBirth," +
" DateOfBirth=@DateOfBirth," +
" EducationLevel=@EducationLevel," +
" EducationInstitution=@EducationInstitution," +
" Employer=@Employer, " +
" Position=@Position " +
" where UserName=@UserName";


SqlCommand cmd = new SqlCommand(updateCommand, conn);

cmd.Parameters.AddWithValue("@FirstNameLastName", txtImePrezime.Text);
cmd.Parameters.AddWithValue("@Gender", rblPol.SelectedValue);//radio button
cmd.Parameters.AddWithValue("@PlaceOfBirth", txtMesto.Text);
cmd.Parameters.AddWithValue("@DateOfBirth", Convert.ToDateTime(txtDatum.Text));
cmd.Parameters.AddWithValue("@EducationLevel", txtObrazovanie.Text);
cmd.Parameters.AddWithValue("@EducationInstitution", txtInstitucija.Text);
cmd.Parameters.AddWithValue("@Employer", txtVrabotenVo.Text);
cmd.Parameters.AddWithValue("@Position", txtPozicija.Text);
cmd.Parameters.AddWithValue("@UserName", User.Identity.Name);

conn.Open();

cmd.ExecuteNonQuery();//error line
conn.Close();


No comments:

Post a Comment