【发布时间】:2011-06-15 18:41:41
【问题描述】:
当我在 Excel 中单击“插入”按钮时,我想将数据插入到 SQL Server 数据库中。
数据在单元格 A2 和 B2 中,这是 excel 中“插入”按钮后面的代码:
Dim HttpReq As New WinHttp.WinHttpRequest
HttpReq.Open "POST", "http://localhost:11121/Student/Insert/", False
HttpReq.Send "jsmith112"
这是我在 VS 中的 Controller 操作代码:
[HttpPost]
public ActionResult Insert(string id)
{
try
{
student.AddToStudents(id);
student.SaveChanges();
return RedirectToAction("Index");
}
catch
{
return View();
}
}
这似乎不起作用,谁能指导我完成这个?
提前致谢
【问题讨论】:
-
什么不起作用?它会抛出错误吗?它甚至击中了您的插入方法吗?故障发生在哪里?
-
您正在尝试对 SQL Server 进行 HTTPPost 到?这甚至是犹太洁食吗?
-
他正在向 ASP.NET MVC Web 服务发送 HTTP POST,而后者又使用 EF 更新数据库。
标签: c# asp.net excel entity-framework http-post