无法更新数据库而不会出错

时间:2015-05-08 08:18:54

标签: c# sql oracle

第1部分,下面的代码是来自另一个类的函数。

public static void updateData(string SqlCommand)
{
    string strConString = ConfigurationManager.ConnectionStrings["SOConnectionString"].ConnectionString;
    OleDbConnection conn = new OleDbConnection(strConString);
    OleDbCommand cmd = new OleDbCommand(SqlCommand, conn);

    try {
        conn.Open();
        cmd.ExecuteNonQuery();
        conn.Close();
    }
    catch (Exception e)
    {
        conn.Close();

    }   
}

这是调用上述函数的代码。

protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
        {

            string ID = txtID.Text;
            string password = txtPassword.Text;
            string name = txtName.Text;
            string position = txtPosition.Text;
            int status = 1;
            string createOn = validate.GetTimestamp(DateTime.Now); ;
            string accessRight;
            if (RadioButton1.Checked)
                accessRight = "Administrator";
            else
                accessRight = "Non-administrator";

            //    ClientScript.RegisterStartupScript(this.GetType(), "yourMessage", "alert('" + ID + "ha " + password + "ha " + status + "ha " + accessRight + "ha " + position + "ha " + name + "ha " + createOn + "');", true);

            string type = (String)Session["type"];


            if (type == "update")
                {
                    string sqlcommand = "UPDATE USERMASTER SET USERPOSITION='"+position+"',USERNAME='"+name+"' WHERE (USERID ='"+ID+"')";
                    readdata.updateData(sqlcommand);
                    Response.Redirect("UserView.aspx");
                }
             else {             
                    if (validate.verifyID(ID) == true)
                    {
                        if (validate.verifyLang((String)Session["Lang"]) == true)
                            lblIDError.Text = "User ID already exist!";
                        else
                            lblIDError.Text = "用户账号已存在!";
                    }
                    else{
                        string sqlcommand = "INSERT INTO USERMASTER (USERID,USERPWD,USERNAME,USERPOSITION,USERACCESSRIGHTS,USERSTATUS,CREATEDATE,CREATEUSERID) VALUES ('" + ID + "','" + password + "','" + name + "','" + position + "','" + accessRight + "','" + status + "', TO_DATE('" + createOn + "'),'" + (string)Session["UserID"] + "')";
                        readdata.updateData(sqlcommand);
                        Response.Redirect("UserView.aspx");

                    }
                }
            }

第1部分代码运行良好的INSERT,但是当来到UPDATE时,它不会显示错误,也不会更新数据。有人知道我的代码有什么问题吗?

1 个答案:

答案 0 :(得分:0)

可能是条件缺少值的更新语句中使用的值。您可以找到使用断路器,这可能会让您对找到答案有所了解,因为您不知道让我在这里发布如何打破并找到它们

下面是要破解的图片并查看带有值的查询。

enter image description here

enter image description here