简体   繁体   English

在SQL Server数据库中插入发布的数据

[英]Insert posted data in SQL Server Database

I am able to post the data from Excel to ASP.NET MVC web service. 我能够将数据从Excel发布到ASP.NET MVC Web服务。 Here is My code for that: 这是我的代码:

Sub SendData()
Dim HttpReq As Object, url As String
Set HttpReq = CreateObject("MSXML2.ServerXMLHTTP")
url = "http://localhost:11121/Student/PostData/"
HttpReq.Open "POST", url, False
HttpReq.SetRequestHeader "Content-Type", "application/x-www-form-urlencoded"
HttpReq.Send "Student=jsmith112"
Debug.Print HttpReq.ResponseText
End Sub

Now, I Want to have a ControllerAction "Insert" That will Insert this posted data in SQLServer Database. 现在,我希望有一个ControllerAction“ Insert”,它将在SQLServer数据库中插入此发布的数据。

What do I need to do to controller action for this? 为此,我需要对控制器采取什么措施?

You need to add <AcceptVerbs(HttpVerbs.POST) > attribute if it's vs2008 or just <HttpPost()> for vs2010 to your controller method, so it receives the posted data. 如果是vs2008,则需要添加<AcceptVerbs(HttpVerbs.POST) >属性,或者将vs2010的<HttpPost()>到控制器方法中,以便它接收发布的数据。 Please note that this is in C#, syntax is slightly different for VB. 请注意,这是在C#中,对于VB,语法略有不同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM