How do I update a row of data using c# and sql -
I am trying to update an image field where the ID is equal to the selected row
I have tried using the following code
string query = "Update ArticlesTBL set ArticleImg = value (@ArticleImg) Where ArticleID = Value (@id)"; SqlCommand myCommand = new SqlCommand (query, myConnection); MyCommand.Parameters.AddWithValue ("@ ArticleImg", "UploadedUserFiles /" + FileUpdate.FileName); MyCommand.Parameters.Add (new SqlParameter ("ID," ID it);) Myinfo.Text = query;
But I do not know where to place commas, brackets etc. in the query string. I have a text box that outputs my command and it shows that I am using UPDATE ArticlesTBL SET ArticleImg = @ArticleImg, where ArticleID = @id but I'm not actually reaching the parameter, I How do I use these parameters? Thanks
is the correct syntax for your update statement And the creator of a SqlParameter that accepts a SqlDbType and an object I also suggest to use AddWithValue for IDs to avoid confusion with Of course, after the order you have prepared the order text, its parameters have been added and the connection need to be executed
string queries = @ "Update Article TBL SET ArticleImg = @ArticleImg where article = @ id";
SqlCommand myCommand = new SqlCommand (query, myConnection); MyCommand.Parameters.AddWithValue ("@ ArticleImg", "UploadedUserFiles /" + FileUpdate.FileName); MyCommand.Parameters.AddWithValue ("ID," ID); MyCommand.ExecuteNonQuery ();
Comments
Post a Comment