这种方法有什么不对吗?我试图添加此方法在Web服务(.asmx)文件中。但它显示我错误。添加完这个之后,即使在.asmx文件中显示相同错误的其他方法也是如此。C# - 添加方法后显示错误
[WebMethod]
public string UpdateEvent(EventsClass es)
{
string cs = ConfigurationManager.ConnectionStrings["DBCS"].ToString();
using (SqlConnection con = new SqlConnection(cs))
{
string qr = "UPDATE Events SET Title = '" + es.Title +
"', DateFrom = '" + es.DateFrom +
"', DateTo = '" + es.DateTo +
"', Location = '" + es.Location +
"', DateTo = '" + es.DateTo +
"', Status = '" + es.Status +
"', Description = '" + es.Description +
"', UpdateDate = '" + es.UpdateDate +
"' WHERE Id = '" + es.Id + "'";
SqlCommand cmd = new SqlCommand(qr, con);
con.Open();
cmd.ExecuteNonQuery();
}
return "1";
}
错误消息是这样的:在AJAX POST方法
System.IndexOutOfRangeException: Index was outside the bounds of the array.
at System.Web.Services.Protocols.HttpServerType..ctor(Type type)
at System.Web.Services.Protocols.HttpServerProtocol.Initialize()
at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing)
错误消息返回:
Failed to load resource: the server responded with a status of 500 (Internal Server Error)
function(){return f&&(c&&!b&&(h=f.length-1,g.push(c)),function d(b){n.each(b,function(b,c){n.isFunction(c)?a.unique&&j.has(c)||f.push(c):c&&c.length&&"string"!==n.type(c)&&d(c)})}(arguments),c&&!b&&i…
一个建议:使用一个StringBuilder,在你的查询命令中使用AddFormat,它更容易构建代码并干净地读取......;) –