I want to know how to use console application to store web api data into sql server database, Do anyone or experts know how to store the data into sql server database using console application to do that, please give me an example, big thanks.
My Code in console application:
HttpClient client = new HttpClient();
Console.WriteLine("Calling Api...");
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/xml"));
var responseTask = client.GetAsync("http://localhost/api/api/Person");
responseTask.Wait();
if (responseTask.IsCompleted)
{
var result = responseTask.Result;
if (result.IsSuccessStatusCode)
{
var messageTask = result.Content.ReadAsStringAsync();
messageTask.Wait();
Console.WriteLine("Message From Api : " + messageTask.Result);
}
MessageBox.Show("Get Completed");
}
API Data:
<ArrayOfPerson xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/API.Models"><Person><ID>10</ID><PersonID>1</PersonID><Mobile></Mobile><Name>Chan King </Name><CreateDate>2019-11-03T00:23:00</CreateDate><ModifyDate>2021-11-06T16:04:00</ModifyDate>
How can i get the value and put into sql server database? Like 10 The 10 can put into the sql server database, and I have 10000+ records in the api