-1

I am new to api, i want to ask how to use console app to store api data into sql server database? I have use console app to call api data successfully already, but how can i use console application to insert api data into sql server database table. my web api came from iis server.

Here is the code for call api data:

using (var client = new WebClient())
            {
                client.Headers.Add("Content-Type:application/xml");
                client.Headers.Add("Accept:application/xml");
                var result = client.DownloadString("http://localhost/test/api/person");
                Console.WriteLine(Environment.NewLine + result);
            }
            MessageBox.Show("Completed");
        }

1 Answer 1

1

If you have successfully fetched data from Api, you can then convert that data into C# Object using newtonsoft deserialize method and use SqlAdapter for inserting that data into a sql Database.

Look into the below attached link for inserting data in db using sqlAdapter.

Using SqlDataAdapter to insert a row

Sign up to request clarification or add additional context in comments.

5 Comments

I can do this coing in console application?
Yes! you can easily do all this in a console application.
But I have more than 10000+ records, will it still works? and do u have an example?
Yes! there is no limitation of how many records you can process. You can have foreach loop for the records and inside the loop you can use code sample attached in the link to insert one by one and a better approach will be to save a data table and than use Sql Bulk insert to insert all the record at once.
Do you have any example to show me please

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.