Tutorial :Update specific rows in LINQ to SQL result set



Question:

I have a page with a form on it and needs a range of dates. Thus I've placed a number of textboxes on the page into which users can type dates. When the user clicks the save button I want to trigger a LINQ update to the SQL Server...all the rows already exist, so I'm just updating existing data. How can I do this? For example, lets say my table looks like this:

  Column Names: Description dateValue  Column Values:                 Birthdate   1/1/1990                 Anniversary 1/10/1992                 Death       1/1/1993  

I want to do something like this:

hupdate.Description("Birthdate").dateValue = TextBox1.Text  hupdate.Description("Anniversary").dateValue = TextBox2.Text  hupdate.Description("Death").dateValue = TextBox3.Text  hconfig.SubmitChanges()  

Is there a way to do this with LINQ?


Solution:1

I don't think there is a way to do that with only LINQ. However, there are other ways to achieve that like:

  • if you use Entity Framework you can use LINQ to query the data, then change the entities (within your c# code) and update the DB via them.
  • Create a stored procedure that updates the data, according to your description this stored procedure doesn't seem like a complicated one.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »