0

将数据插入 Access 2003 .mdb 数据库时出现问题。 这个解决方案对我不起作用!

例外:

多步 OLE DB 操作产生错误。检查每个 OLE DB 状态值(如果可用)。没有做任何工作。

app.config我在文件中的连接字符串:

<connectionStrings>
    <add name="UI.Properties.Settings.ZangolehDbConnectionString"
        connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\Db\ZangolehDb.mdb;"
        providerName="System.Data.OleDb" />
  </connectionStrings>

在我的代码中...

更新:

public static bool Insert(GlobalEvent globalEvent)
{
    bool result = false;
    using (OleDbConnection connection = new OleDbConnection(DataAccess.ConnectionString))
    {
        OleDbCommand command = connection.CreateCommand();
        command.CommandText = "INSERT INTO UserEvents(Title, Comment, Volume, EventType, EventDate, MediaSource)VALUES(@Title, @Comment, @Volume, @EventType, @EventDate, @MediaSource)";
        command.CommandType = CommandType.Text;

        command.Parameters.AddWithValue("@Title", globalEvent.Title);
        command.Parameters.AddWithValue("@Comment", globalEvent.Comment);
        command.Parameters.AddWithValue("@Volume", globalEvent.Volume);
        command.Parameters.AddWithValue("@EventType", globalEvent.EventType);
        command.Parameters.AddWithValue("@EventDate", globalEvent.EventDate);
        command.Parameters.AddWithValue("@MediaSource", globalEvent.MediaSource);
        try
        {
            command.Connection.Open();
            result = command.ExecuteNonQuery() > 0; // <-- Throws Exception...
            command.Connection.Close();
        }
        catch { result = false; }
        finally
        {
            command.Connection.Close();
        }

        return result;
    }
}

这似乎是一个没有任何答案的著名问题!:(

4

1 回答 1

-1

您将错误的值传递给查询。

于 2011-12-21T13:42:48.077 回答