如何解决在accss数据库上使用UpdateCommand时找不到处理程序
我正在html页面中构建游戏。
我正在使用的数据库是访问。我正在尝试从javascript
调用处理程序,但出现错误:jquery-2.1.1.min.js:4 GET http://localhost:52183/UpdateHandler.ashx?myName=rhry&myMin=00&mySec=00&myGold=0&mySilver=0&myBronze=0 404 (Not Found)
在处理程序中,我正在尝试更新数据库。 (当在asp.net Web应用程序页面的asp按钮后面使用相同的代码时,它可以工作,但在使用处理程序时则无效)。
我不明白为什么会这样。
javascript :
$.get("UpdateHandler.ashx",{
myName: readCookie("playerName")//sent players table,myMin: pad(parseInt(totalSeconds / 60)),mySec: pad(totalSeconds % 60),myGold: document.getElementById("goldScore").innerHTML,mySilver: document.getElementById("silverScore").innerHTML,myBronze: document.getElementById("bronzeScore").innerHTML
},function (data,status) {
if (status == "success") {
//printing the response in the console
console.log(data);
}
});
处理程序:
public class Handler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
string myName = context.Request["myName"];
string myMin = context.Request["myMin"];
string mySec = context.Request["mySec"];
string myGold = context.Request["myGold"];
string mySilver = context.Request["mySilver"];
string myBronze = context.Request["myBronze"];
OleDbConnection conn = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + HttpContext.Current.Server.MapPath("app_data/players.accdb") + ";");
OleDbCommand cmd = conn.CreateCommand();
OleDbDataAdapter da = new OleDbDataAdapter("select * from players WHERE Pname = '" + myName + "'",conn);
conn.Open();
string query = "UPDATE players SET fullTime = '00:" + myMin + ":" + mySec + "',Pgold = '" + myGold + "',Psilver = '" + mySilver + "',Pbronze = '" + myBronze + "' WHERE Pname = '" + myName + "'";
var accessUpdateCommand = new OleDbCommand(query,conn);
da.UpdateCommand = accessUpdateCommand;
da.UpdateCommand.ExecuteNonQuery();
context.Response.Write("updatedDataBase");
conn.Close();
}
public bool IsReusable
{
get
{
return true;
}
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。