Note that there are some explanatory texts on larger screens.

plurals
  1. POC# update SQL Server table
    text
    copied!<p>I've tried to write an <code>update</code> statement that will update some information in my SQL Server table</p> <p>Here is my code so far, I can't see the issue.</p> <pre><code>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"; } } } } </code></pre> <p>I have also searched a lot, but it's exactly the same I find. Maybe it's something about the SQL query.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload