TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Vikas
NA
831
195.5k
After getting data through api, how to post in sql using c#
Mar 18 2020 4:19 AM
I have C# Console Application where I'm getting data from google-news-api and after that I want to post whole data to my sql server. So how is it possible
namespace
ConsoleApp {
class
Program {
static
void
Main(
string
[] args) {
SqlConnection conn =
new
SqlConnection(@
"Server=SQLEXPRESS;Initial Catalog=testingnews;User Id=abctesting;Password=sabc;"
);
conn.Open();
SqlCommand cmd =
new
SqlCommand(
"insert into newstbl values ('50AE4E66-07C0-4AB0-936B-2778AFCB9787', '', '', '', '', '', '', '', '', '', '', '', 0, '', 0, '', 1, 0, '')"
, conn);
SqlDataReader reader = cmd.ExecuteReader();
while
(reader.Read()) {
Console.WriteLine(
"{0},{1}"
, reader.GetString(0), reader.GetString(1));
Console.ReadLine();
}
reader.Close();
conn.Close();
try
{
GetNewsDetails().Wait();
}
catch
(Exception ex) {}
}
public
static
async Task <
string
> GetNewsDetails() {
using
(var _http =
new
HttpClient()) {
_http.BaseAddress =
new
Uri(
"https://newsapi.org/v2/"
);
_http.DefaultRequestHeaders.Clear();
_http.DefaultRequestHeaders.Accept.Add(
new
MediaTypeWithQualityHeaderValue(
"application/json"
));
HttpResponseMessage response = await _http.GetAsync(
"everything?sources=&q=bbc-news&sortBy=publishedAt&pageSize=80&apiKey=4dbc17e007ab436fb66416009dfb59a8"
);
response.EnsureSuccessStatusCode();
using
(HttpContent content = response.Content) {
string
responseBody = await content.ReadAsStringAsync();
Console.WriteLine(responseBody); // In
responseBody I'm getting multiple data
Console.ReadLine();
}
}
return
"objNewsRoot"
;
}
}
}
as per my logic some changes in line no 6 so please help me how to post array type data.
Reply
Answers (
3
)
How would you setup backend database?
mdi parent and child