Inserting into an Oracle table with auto increment

Topics: Data Access Application Block
Sep 15, 2011 at 1:01 PM

Hi,

Is it possible to insert into an Oracle table that has an auto-increment primary key column using the UpdateDataset method and the GetInsertCommand method?

I am using the following code at the moment and it is does not seem to be working:

strSQL = "select * from myTable"

DbCommand cmd = myEnterpriseLibraryDatabase.GetSqlStringCommand(strSQL);                       

cmd.Connection = myEnterpriseLibraryDatabase.CreateConnection();
DbCommandBuilder cb = myEnterpriseLibraryDatabase.DbProviderFactory.CreateCommandBuilder();                       

cb.DataAdapter = myEnterpriseLibraryDatabase.GetDataAdapter();                       

cb.DataAdapter.SelectCommand = cmd;

//Get the auto-built Insert command:                      

cb.DataAdapter.InsertCommand = cb.GetInsertCommand(true);

rowsAffected = myEnterpriseLibraryDatabase.UpdateDataSet(comparableEditionDataset, comparableEditionDataset.COMPARABLE_EDITION.TableName, cb.DataAdapter.InsertCommand, null, null, UpdateBehavior.Transactional);

Otherwise is there another way of performing the insert?

Thanks in advance.

 

 

 

 

Sep 16, 2011 at 9:22 AM

Hi,

I assume this would work on Oracle. I'm just wondering if you have updated your dataset.

 

Noel Angelo Bolasoc
Avanade Software
Avanade, Inc.
Contact Us