J
Jason
Can anyone tell me why this code won't update the datasource? It
always comes back with this DBConcurrency Exception:
"Concurrency violation: the UpdateCommand affected 0 of the expected 1
records."
The database is Oracle. Here's the table creation SQL for the table
I'm querying:
CREATE TABLE TEST
(
ID INT,
email CHAR(1),
NAME CHAR(1),
CONSTRAINT PK_test PRIMARY KEY (ID )
)
Here's the code in its entirety:
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Data;
using System.Data.Odbc;
namespace DatabaseTester {
static class Program {
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main() {
DataSet data = new DataSet();
OdbcConnection conn = new OdbcConnection(
"DSN=ORACLE-DATABASE;UID=user;PWD=password!;" );
OdbcDataAdapter da = new OdbcDataAdapter( "Select id, email, name
from test", conn );
da.MissingSchemaAction = MissingSchemaAction.AddWithKey;
//DataTable[] t = da.FillSchema( data, SchemaType.Source );
da.Fill( data );
data.AcceptChanges();
OdbcCommandBuilder cb = new OdbcCommandBuilder( da );
da.InsertCommand = cb.GetInsertCommand();
da.UpdateCommand = cb.GetUpdateCommand();
da.DeleteCommand = cb.GetDeleteCommand();
MessageBox.Show( "Before: " + data.Tables[0].Rows[0][1].ToString()
);
data.Tables[0].Rows[0][1] = "a";
MessageBox.Show( "After: " + data.Tables[0].Rows[0][1].ToString() );
if( data.HasChanges() ) {
MessageBox.Show( "It has changes." );
try {
MessageBox.Show( "Returns: " + da.Update( data ).ToString() );
data.AcceptChanges();
}
catch( DBConcurrencyException e ) {
MessageBox.Show( e.ToString() );
}
}
conn.Close();
}
}
}
always comes back with this DBConcurrency Exception:
"Concurrency violation: the UpdateCommand affected 0 of the expected 1
records."
The database is Oracle. Here's the table creation SQL for the table
I'm querying:
CREATE TABLE TEST
(
ID INT,
email CHAR(1),
NAME CHAR(1),
CONSTRAINT PK_test PRIMARY KEY (ID )
)
Here's the code in its entirety:
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Data;
using System.Data.Odbc;
namespace DatabaseTester {
static class Program {
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main() {
DataSet data = new DataSet();
OdbcConnection conn = new OdbcConnection(
"DSN=ORACLE-DATABASE;UID=user;PWD=password!;" );
OdbcDataAdapter da = new OdbcDataAdapter( "Select id, email, name
from test", conn );
da.MissingSchemaAction = MissingSchemaAction.AddWithKey;
//DataTable[] t = da.FillSchema( data, SchemaType.Source );
da.Fill( data );
data.AcceptChanges();
OdbcCommandBuilder cb = new OdbcCommandBuilder( da );
da.InsertCommand = cb.GetInsertCommand();
da.UpdateCommand = cb.GetUpdateCommand();
da.DeleteCommand = cb.GetDeleteCommand();
MessageBox.Show( "Before: " + data.Tables[0].Rows[0][1].ToString()
);
data.Tables[0].Rows[0][1] = "a";
MessageBox.Show( "After: " + data.Tables[0].Rows[0][1].ToString() );
if( data.HasChanges() ) {
MessageBox.Show( "It has changes." );
try {
MessageBox.Show( "Returns: " + da.Update( data ).ToString() );
data.AcceptChanges();
}
catch( DBConcurrencyException e ) {
MessageBox.Show( e.ToString() );
}
}
conn.Close();
}
}
}