Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/307.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.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# Access 2007数据库未更新_C#_Ms Access 2007_Updating - Fatal编程技术网

C# Access 2007数据库未更新

C# Access 2007数据库未更新,c#,ms-access-2007,updating,C#,Ms Access 2007,Updating,我正在开发一个使用Access数据库的.Net桌面应用程序。我正在使用Contacts表单并尝试更改Category字段,该字段在值的组合框中有多个选项。我试图设置的值在选项列表中,但它不起任何作用。这是我的密码。请说明发生了什么事。该代码似乎适用于DELETE命令 string list = string.Join(", ", f); string ConnStr = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Sourc

我正在开发一个使用Access数据库的.Net桌面应用程序。我正在使用Contacts表单并尝试更改Category字段,该字段在值的组合框中有多个选项。我试图设置的值在选项列表中,但它不起任何作用。这是我的密码。请说明发生了什么事。该代码似乎适用于DELETE命令

        string list = string.Join(", ", f);

        string ConnStr = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + txtDB.Text + "";

        string ComStr = "UPDATE Contacts SET Category = ? where [E-mail Address] in (?)";
        using (OleDbConnection con = new OleDbConnection(ConnStr))
        {
            con.Open();
            using (OleDbCommand com = new OleDbCommand(ComStr, con))
            {
                com.Parameters.AddWithValue("List", list);
                com.Parameters.AddWithValue("Category", "Не получава мейли");
                com.ExecuteNonQuery();
            }
            con.Close();
        } 

我认为这应该奏效:

string ComStr = "UPDATE Contacts SET Category = @Category where [E-mail Address] in @List";
            using (OleDbConnection con = new OleDbConnection(ConnStr))
            {
                con.Open();
                using (OleDbCommand com = new OleDbCommand(ComStr, con))
                {

                    com.Parameters.AddWithValue("@Category", "Не получава мейли");
                    com.Parameters.AddWithValue("@List", list);
                    com.ExecuteNonQuery();
                }
                con.Close();
            } 

我找到了答案。列表中的每一项都必须在。。。好吧,我不知道这个词,但这是我的工作代码:

    string list = string.Join("', '", f);
    string l = "'" + list + "'";

    string ConnStr = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + txtDB.Text + "";

    string ComStr = "UPDATE Contacts SET Category = @Category where [E-mail Address] in (" + l + ")";
    using (OleDbConnection con = new OleDbConnection(ConnStr))
    {
        con.Open();
        using (OleDbCommand com = new OleDbCommand(ComStr, con))
        {

            com.Parameters.AddWithValue("Category", "Не получава мейли");
            com.ExecuteNonQuery();
        }
        con.Close();
    } 

感谢您的提示和时间助手。

您必须按照查询中出现的相同顺序添加参数。它对数据库仍然没有任何作用。