多步 OLE DB 操作生成错误
我在将数据插入 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
重要的是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#
您向查询传递了错误的值。
You're passing wrong values to the query.