How to insert Windows Form Data Into Database Using Web API?
Loading
How to insert Windows Form Data Into Database Using Web API?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Srinivasan RamamoorthiPosted Oct 28, 2021, 1:24 PM
Sachin SinghPosted Oct 28, 2021, 4:47 AM
use HttpClient as shown below
public void Save()
{
static HttpClient client = new HttpClient();
client.BaseAddress = new Uri("http://localhost:4354/api/");
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(
new MediaTypeWithQualityHeaderValue("application/json"));
var product = new Product() { Name = txtProd.Text Price = txtPrice.Text, Category = txtcat.Text };
var response = await client.PostAsJsonAsync("products", product); // here //products is the controller(Endpoint) name
}
for creating api follow my article :- https://www.sharpencode.com/article/WebApi/implementing-crud
Kirtesh ShahPosted Oct 28, 2021, 4:46 AM