多步OLE DB操作生成错误

时间:2010-12-29 11:47:29

标签: c# exception connection-string oledb oledbconnection

将数据插入Access 2003 .mdb数据库时出现问题。 This solution对我不起作用!

例外:

  

多步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;
    }
}

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

1 个答案:

答案 0 :(得分:-1)

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

相关问题