日期:2014-05-16  浏览次数:20672 次

ajax 更新/插入数据库 出错!internal server error!
C#代码
C# code
 [WebMethod]
    public static string cp(string yp, string np)
    {
        object obj = System.Web.HttpContext.Current.Session["username"];
        string username = "";
        if (obj != null)
            username = obj.ToString();
        StringBuilder strSql = new StringBuilder();
        strSql.Append("select * from Users where UserName = @UserName");
        OleDbParameter[] parameter = {
                    new OleDbParameter("@UserName", OleDbType.VarChar,20)};
        parameter[0].Value = username;

        OleDbDataReader dr = SqlHelper.GetRead(strSql.ToString(), parameter);
        if (dr.Read())
        {
            string userpwd = dr["UserPwd"].ToString();
            dr.Close();
            if (yp == userpwd)
            {
                StringBuilder strSql2 = new StringBuilder();
                strSql2.Append("update Users set UserPwd = @UserPwd where UserName = @UserName");
                OleDbParameter[] parameter2 = {
                            new OleDbParameter("@UserPwd", OleDbType.VarChar,32),
                            new OleDbParameter("@UserName", OleDbType.VarChar,20)};
                parameter2[0].Value = np;
                parameter2[1].Value = username;

                int rows = SqlHelper.ExecuteSql(strSql2.ToString(), parameter2);
                if (rows > 0)
                    return "200";
                else return "400";
            }
            else return "400";
        }
        else
        {
            dr.Close();
            return "201";
        }
    }


javascript代码:
JScript code


    $("#csu").click(function () {
        if ($("#np").val() == $("#np2").val()) {
            $("#csu").attr("disabled", "disabled");
            $.ajax({
                type: "post",
                url: "Sys_Main.aspx/cp",
                data: "{'yp':'" + $("#yp").val() + "','np':'" + $("#np").val() + "'}",
                dataType: "json",
                contentType: "application/json; charset=utf-8",
                success: function (data) {
                    var obj = jQuery.parseJSON(data)
                    switch (data.d) {
                        case "200":
                            $("#info").text("密码更改成功!");
                            $("#yp").val("");
                            $("#np").val("");
                            $("#np2").val("");
                            break;
                        case "400":
                            $("#info").text("密码更改失败!");
                            break;
                    }
                    $("#csu").removeAttr("disabled");
                },
                error: function (XMLHttpRequest, textStatus,
errorThrown) {
                    alert("错误:" + errorThrown);
                }
            });
        }
        else $("#info").text("两次密码输入不一样!");
        return false;
    });



在VS上调试 可以通过!但是发布在IIS7之后,出错了!
经过测试,只要我将密码输入错误!就能成功回显“400"
但是一旦我填写了正确的密码的时候,运行到 “update”语句的时候就会显示 internal server error!

想爆脑袋了!不知道为什么会这种这种情况!
希望大家能够说说你们的见解!

------解决方案--------------------
if (yp == userpwd)
{
StringBuilder strSql2 =