|
-
Nov 16th, 2007, 03:39 PM
#1
Thread Starter
Hyperactive Member
[2.0] Please help...dataadapter not inserting records
I am trying to use data adapter to insert records into a table. but for some reason, no records get inserted. The data base is oracle.
DataGateway aDataGateway = new DataGateway();
OracleConnection aMbsfas91Connection = aDataGateway.GetMbsFas91Connection();
aMbsfas91Connection.Open();
OracleDataAdapter adp = new OracleDataAdapter(sqlDataAdapter, aMbsfas91Connection);
OracleCommand command = new OracleCommand(ssqlInsert, aMbsfas91Connection);command.CommandType = CommandType.Text;
command.Parameters.Add("CUSIP", OracleType.VarChar, 20, "CUSIP");
command.Parameters.Add("SEC_ID", OracleType.VarChar, 20, "SEC_ID");
adp.InsertCommand = command;
adp.Fill(aDataTableMbsDeals);
adp.Update(aDataTableMbsDeals);
aMbsfas91Connection.Close();
No errors show up but the data doesn't get updated
-
Nov 16th, 2007, 11:41 PM
#2
Re: [2.0] Please help...dataadapter not inserting records
The problem is that all the DataRows in your DataTable have their RowState set to Unchanged, so when you call Update there are no new rows in the DataTable to insert. All the DataRows must have their RowState set to Added if they're to be inserted into a table.
When you call Fill the DataAdapter will create all the DataRows and then add them to the DataTable, at which point their RowState is Added. At that point the default behaviour of the DataAdapter is to call the table's AcceptChanges method, which sets all the RowStates to Unchanged, then Fill returns.
In order to override that default behaviour you have to set the AcceptChangesDuringFill property the DataAdapter to False.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|