I want to insert data into SQL Server database when I click “Insert” button in excel.
The data is in Cells A2 and B2 and here is the code behind the “Insert” button in excel:
Dim HttpReq As New WinHttp.WinHttpRequest
HttpReq.Open "POST", "http://localhost:11121/Student/Insert/", False
HttpReq.Send "jsmith112"
Here is my code for the Controller action in VS:
[HttpPost]
public ActionResult Insert(string id)
{
try
{
student.AddToStudents(id);
student.SaveChanges();
return RedirectToAction("Index");
}
catch
{
return View();
}
}
This doesn’t seem to be working, could anyone guide me into finishing this?
Thanks in advance
Just change the POST to
and then map the route
and then in your controller you can check if id is empty, if not then make a new user
also, sometimes I do things like this
and then you could parse out what the things are..
as a side note and if you were making more end points for your service, you might consider using GET, POST, PUT, DELETE instead of actually having “Insert” in the URI. REST.