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;
}
}
これは答えのない有名な問題のようです!!! :(