I've tried to write an update statement that will update some information in my SQL Server table
Here is my code so far, I can't see the issue.
protected void Page_Load(object sender, EventArgs e) { FirstNameEdit.Text = Session["FirstName"].ToString(); LastNameEdit.Text = Session["LastName"].ToString(); } protected void SubmitEdit_Click(object sender, EventArgs e) { if (FirstNameEdit.Text == "") { StatusMessage.Text = "Indtast venligst dit fornavn. "; } else { if (LastNameEdit.Text == "") { StatusMessage.Text = "Indtast venligst dit efternavn. "; } else { try { SqlConnection connection = new SqlConnection("Data Source=localhost;Initial Catalog=Break;Integrated Security=True"); SqlCommand command = new SqlCommand("SELECT * FROM Users", connection); command.Connection.Open(); string querystr = "UPDATE Users SET User_FirstName='@User_FirstName', User_LastName='@User_LastName' WHERE User_ID='@User_ID'"; SqlCommand query = new SqlCommand(querystr, connection); string User_ID = Session["ID"].ToString(); string User_FirstName = FirstNameEdit.Text; string User_LastName = LastNameEdit.Text; query.Parameters.Add("@User_ID", User_ID); query.Parameters.Add("@User_FirstName", User_FirstName); query.Parameters.Add("@User_LastName", User_LastName); query.ExecuteNonQuery(); string FirstName = FirstNameEdit.Text; Session.Add("FirstName", FirstName); string LastName = LastNameEdit.Text; Session.Add("LastName", LastName); StatusMessage.Text = "Din profil er opdateret"; command.Connection.Close(); } catch { StatusMessage.Text = "Noget er galt, prøv lidt senere"; } } } } I have also searched a lot, but it's exactly the same I find. Maybe it's something about the SQL query.
'wrapping your parameters it should just beUser_FirstName=@User_FirstName