Note that there are some explanatory texts on larger screens.

plurals
  1. POTSQL: Updating multiple columns not working?? (ASP.NET C#)
    text
    copied!<p>I have this stored procedure</p> <pre><code>CREATE PROCEDURE spEditInfo @username nvarchar(64), @password nvarchar(64), @firstname nvarchar(64), @middlename nvarchar(64), @lastname nvarchar(64), @email nvarchar(64) AS UPDATE Users SET password=@password, firstname=@firstname, middlename=@middlename, lastname=@lastname, email=@email WHERE username=@username; </code></pre> <p>Here is the problem, though. No matter what values I throw in as the remaining parameters, only password gets changed. Any ideas why?</p> <p>Here is my calling code:</p> <pre><code> SqlCommand cmd = new SqlCommand("spEditInfo", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("username", SqlDbType.NVarChar, 64); cmd.Parameters.Add("password", SqlDbType.NVarChar, 64); cmd.Parameters.Add("firstname", SqlDbType.NVarChar, 64); cmd.Parameters.Add("middlename", SqlDbType.NVarChar, 64); cmd.Parameters.Add("lastname", SqlDbType.NVarChar, 64); cmd.Parameters.Add("email", SqlDbType.NVarChar, 64); cmd.Parameters["username"].Value = Username.Text; cmd.Parameters["password"].Value = Password.Text; cmd.Parameters["firstname"].Value = FirstName.Text; cmd.Parameters["middlename"].Value = MiddleName.Text; cmd.Parameters["lastname"].Value = LastName.Text; cmd.Parameters["email"].Value = Email.Text; conn.Open(); cmd.ExecuteNonQuery(); conn.Close(); </code></pre> <p>EDIT: Ok, I admit I have been wasting time looking at the wrong end. I have the values for the controls initialized during page_load. It is overwriting all of the changes, except for password, which I don't show.</p> <p>Any suggestions on how to improve this?? I want the committed data to show up on the form.</p> <p>EDIT: Back to square 1. It seems the data is passed perfectly to the SP, because I have the SP now do a little logging of the params to a txt file outside. However, it seems that the values are not being updated when called by my ASP.NET page. This is peculiar, as with manual execution, the SP works, just not when called via my code.</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