V
VR
Hi,
I am getting the following exception when trying to update
a dataset using data adapater and a command builder:
"Execute requires the command to have a transaction object
when the connection assigned to the command is in a
pending local transaction. The Transaction property of
the command has not been initialized."
Here is the code:
DataSet oDS = ...;
OleDbConnection oConnection = ...;
OleDbTransaction oTransaction = ...;
// without this line it works...
oTransaction = oConnection.BeginTransaction();
OleDbDataAdapter oDA = null;
OleDbCommandBuilder oCmdBuilder = null;
oDA = new OleDbDataAdapter("SELECT * FROM " + oDS.Tables
[0].TableName, oConnection);
DataSet oChangesDS = oDS.GetChanges();
if (oChangesDS != null)
{
oCmdBuilder = new OleDbCommandBuilder(oDA);
oCmdBuilder.QuotePrefix = "[";
oCmdBuilder.QuoteSuffix = "]";
oDA.Update(oDS, oDS.Tables[0].TableName);
oDS.AcceptChanges();
}
....
If I don't start transaction, everything works.
I tried setting the transaction property of the command
builder:
oCmdBuilder.GetUpdateCommand().Transaction = oTransaction;
and/or Transaction of data adapter:
oDA.SelectCommand.Transaction = oTransaction;
No luck.
Please help.
Thanks,
VR
I am getting the following exception when trying to update
a dataset using data adapater and a command builder:
"Execute requires the command to have a transaction object
when the connection assigned to the command is in a
pending local transaction. The Transaction property of
the command has not been initialized."
Here is the code:
DataSet oDS = ...;
OleDbConnection oConnection = ...;
OleDbTransaction oTransaction = ...;
// without this line it works...
oTransaction = oConnection.BeginTransaction();
OleDbDataAdapter oDA = null;
OleDbCommandBuilder oCmdBuilder = null;
oDA = new OleDbDataAdapter("SELECT * FROM " + oDS.Tables
[0].TableName, oConnection);
DataSet oChangesDS = oDS.GetChanges();
if (oChangesDS != null)
{
oCmdBuilder = new OleDbCommandBuilder(oDA);
oCmdBuilder.QuotePrefix = "[";
oCmdBuilder.QuoteSuffix = "]";
oDA.Update(oDS, oDS.Tables[0].TableName);
oDS.AcceptChanges();
}
....
If I don't start transaction, everything works.
I tried setting the transaction property of the command
builder:
oCmdBuilder.GetUpdateCommand().Transaction = oTransaction;
and/or Transaction of data adapter:
oDA.SelectCommand.Transaction = oTransaction;
No luck.
Please help.
Thanks,
VR