Alexandra Wilkinson Alexandra Wilkinson - 1 year ago 76
SQL Question

ASP.Net Web App does everything but Update Database (C# MS SQL)

I am not the greatest at explaining things, so here it goes:
I have created an ASP.Net website using C# and MS SQL Server.

Debugging in Visual Studio on my server I have been able to insert data into my database, load it back, and delete it. But I have not been able to update at any point using any method. I do not get any errors, and my code posts back to my page that the database has updated.

For my parameters I have tried:

updateDB.Parameters.Add(new SqlParameter("@winIT", SqlDbType.Text));
updateDB.Parameters["@winIT"].Value = winIT.Text;
updateDB.Parameters.Add("@sigWinIT", SqlDbType.Text);
updateDB.Parameters["@sigWinIT"].Value = sigWinIT.Text;
updateDB.Parametrs.AddWithValue("@sigIT", sigIt.Text);

My update command is: (I have tried with and without quotes around @badge.)

SqlCommand updateDB = new SqlCommand("UPDATE UserRequest SET ur_winIT =@winIT, ur_sigWinIT=@sigWinIT,ur_IGTIT = @IGTIT, " + " ur_sigIGTIT = @sigIGTIT" + "WHERE ur_badgeNum ='@badge'", con);
MessageBack2.Text = "Connection to Database Failed. Could not Update, please try again.";

Answer Source

I was able to get it to update! I had to add [] around each database item.

SqlCommand updateDB = new SqlCommand("UPDATE UserRequest SET [ur_winIT]=@winIT, [ur_sigWinIT]=@sigWinIT WHERE [ur_badgeNum] = @badge", con);

Thanks for all your help!