多步OLE DB操作生成错误

问题描述 投票:0回答:2

我在将数据插入 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;
    }
}

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

c# exception connection-string oledb oledbconnection
2个回答
0
投票

重要的是Access中的Long整型数据类型相当于C#中的int,而不是C#中的long


-1
投票

您向查询传递了错误的值。

© www.soinside.com 2019 - 2024. All rights reserved.