I’m receiving a JSON result in my ASP webapi SaveChanges action. I want to take that JSON string and convert it to an SQL Update string.
Just wondering if anyone knows what the best way to convert a JSON string to an SQL Update Query.
Here is an example of the JSON string I am receiving and the equivalent SQL:
[{"ContactID":3,"FirstName":"Tester","LastName":"Tester","DepartmentName":"Dept"}]
Which would equate to:
UPDATE Contact Set FirstName = 'Tester', LastName = 'Tester', DepartmentName = 'Dept' Where ContactID = 3
Currently I’m doing a pretty nasty for loop on a JArray to build the SQL update string. So if anyone has any other cleaner methods that would be great.
I wrote a store procedure based on Phil’s parseJSON function, it works and have not discovered any bugs yet.
link to My code