Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# MS Access数据库未更新_C#_Database_Ms Access - Fatal编程技术网

C# MS Access数据库未更新

C# MS Access数据库未更新,c#,database,ms-access,C#,Database,Ms Access,有人能告诉我为什么我的数据库没有更新吗?这是我的密码: protected void editSection_selected(object sender, EventArgs e) { int index = grdPhone.SelectedIndex; GridViewRow row = grdPhone.Rows[index+1]; string values = ((DropDownList)sender).SelectedValue; int temp

有人能告诉我为什么我的数据库没有更新吗?这是我的密码:

protected void editSection_selected(object sender, EventArgs e) {
    int index = grdPhone.SelectedIndex;
    GridViewRow row = grdPhone.Rows[index+1];
    string values = ((DropDownList)sender).SelectedValue;
    int tempVal = Convert.ToInt32(values);
    int caseage = Convert.ToInt32(keyId);
    int value = tempVal;
    /*OleDbConnection con = new OleDbConnection(strConnstring);
    //string query = "Update Categories set HRS_LEVEL_AMOUNT=" + tempVal + " where parent_id=65 and ID=" + caseage;
    string query = "Delete HRS_LEVEL_AMOUNT from Categories where parent_id=65 and id=" + caseage;
    OleDbCommand cmd = new OleDbCommand(query, con);
    con.Open();
    cmd.ExecuteNonQuery();
    con.Dispose();
    cmd.Dispose();
    con.Close();
    accPhoneNumbers.UpdateCommand = "Update Categories set HRS_LEVEL_AMOUNT=" + tempVal + " where parent_id=65 and ID=" + caseage;
    */
    string str = "UPDATE Categories SET HRS_LEVEL_AMOUNT = ? WHERE ID=?";
    using (OleDbConnection con = new OleDbConnection(strConnstring))
    {
        using (OleDbCommand cmd = new OleDbCommand(str, con))
        {

            cmd.CommandType = CommandType.Text;
            cmd.Parameters.AddWithValue("HRS_LEVEL_AMOUNT", tempVal);
            cmd.Parameters.AddWithValue("ID", caseage);
            con.Open();
            cmd.ExecuteNonQuery();
        }
    }
    Label1.Text += " editSection Success! (B) " + tempVal;
}
注释部分是我的第一个解决方案(包括AccPhoneNumber.UpdateCommand)。
我真的需要你们的帮助。

我希望这能帮助你们:

string str = "UPDATE Categories SET HRS_LEVEL_AMOUNT = @value1 WHERE ID=@value2";
using (OleDbConnection con = new OleDbConnection(strConnstring))
{
    using (OleDbCommand cmd = new OleDbCommand(str, con))
    {

        cmd.CommandType = CommandType.Text;
        cmd.Parameters.AddWithValue("@value1", tempVal);
        cmd.Parameters.AddWithValue("@value2", caseage);
        con.Open();
        cmd.ExecuteNonQuery();
        con.close();
    }
}

有关更多信息,请访问此

尝试获取ExecuteNonQuery命令的返回值。如果任何记录已更新,则该值应大于0。如果为零,则where条件失败。还要将连接字符串添加到代码中。数据库位于何处,这是什么类型的项目(WinForms、ASP.NET…)请尝试使用F11一步一步地调试您的代码您是否没有相同的占位符字符串进行替换?“HRS\u LEVEL\u AMOUNT=?其中ID=?”是的。ExecuteOnQuery为零。但“ID”的值存在于数据库中。为什么?尝试用已知值替换ID。如果有效,则ID有问题。