Send data from C# string object to SQL Server Database

lcorcoran1

New member
Joined
Jan 20, 2023
Messages
3
Programming Experience
Beginner
Hello,

I have a console app that calls an API and gets a response in JSON

I'd like to the "upload" this json into an existing SQL Server Table.

Is this possible?
 
What is the schema of the SQL table? How does it map to the JSON string value that you get from the API?

Or do you just need to record the raw JSON response as a column in the table? Will you ever need to search for a value in that JSON once it is put into a column in the table?

Moving this thread to something more database related.
 
The JSON returns
JSON:
{
"ID":1212,
"Name":Test
}
My table has just these 2 columns


I'd like to map these to the columns in the database
 
Last edited:
I doubt that would actually work. That looks like invalid JSON.
 
I see. In the future please don't that. This forum is a more traditional forum that has posts going chronologically. It's not like StackOverflow where people go back and massage questions and posts based on ongoing comments. It make post #4 look like I was on drugs or blind if a person was reading the posts chronologically -- not that I'm blind from time to time. :) Good thing post #5 explains what happened.

Anyway, what you need to do is parse the JSON. JSON.NET is very good and easy to work with, but you can also use the MS JSON serializer/deserializer. After parsing the JSON, make a few simple ADO.NET calls to connect to your database and insert a row passing in the parsed values.
 
If I was doing this I'd have Entity Framework plumbed into the DB, it'd have made a model class representing a row in this table, I'd use some json serializer to deserialize this json into an instance of the model, add it to the EF context and save. If I had millions to do look at some lib that does bulk upload like borisdj's bulk EF extensions
 
Need to fix this JSON first :)

1691883037576.png
 
Back
Top Bottom