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

"itemprop =" text ">

is the correct syntax for your update statement

  string queries = @ "Update Article TBL SET ArticleImg = @ArticleImg where article = @ id";  

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

  SqlCommand myCommand = new SqlCommand (query, myConnection); MyCommand.Parameters.AddWithValue ("@ ArticleImg", "UploadedUserFiles /" + FileUpdate.FileName); MyCommand.Parameters.AddWithValue ("ID," ID); MyCommand.ExecuteNonQuery ();  

Of course, after the order you have prepared the order text, its parameters have been added and the connection need to be executed


Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -