I have this situation where I need to modify the insert command after is generated by the sqlcommandbuilder, and I need to do this to get the scope_identity after the insert. Part of the code is :
adapterClients = new SqlDataAdapter (cmdClients, connString);
SqlCommandBuilder cmdBuilder = new SqlCommandBuilder (adapterClients);
adapterClients.Fill (dataSet, "Clients");
adapterClients.InsertCommand.CommandText += "; select ClientID = SCOPE_IDENTITY()";
adapterClients.InsertCommand.UpdatedRowSource = UpdateRowSource.FirstReturnedRecord;
I get a null exception on adapterClients.InsertCommand.
The insert command that is automatically generated will be part of the builder, not the adapter. So you will want to use the follow to retrieve the insert command:
So, depending on what exactly you are trying to do, you could use the following to (1) set the generated insert command to the adapter and then (2) modify the generated insert command to include the retrieval of the scope_identity.