多步 OLE DB 操作生成错误

发布于 2024-10-09 17:25:17 字数 1922 浏览 0 评论 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;
    }
}

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

I have a problem while inserting data into an Access 2003 .mdb database.
This solution doesn't work for me!

Exception:

Multiple-step OLE DB operation
generated errors. Check each OLE DB
status value, if available. No work
was done.

My connection string in app.config file:

<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>

In my code...

UPDATED:

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

It seems this is a famous problem without any answer!!! :(

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

静谧 2024-10-16 17:25:17

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

The important thing is that the Long integer data type in Access is equivalent to int in C#, not long in C#

谁人与我共长歌 2024-10-16 17:25:17

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

You're passing wrong values to the query.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文