I use dataset’ Insert() method to insert data to database.Like:
public void InsertData()
{
ATableAdapter a = new ATableAdapter();
a.Insert(//some parameters); //step 1: OK
BTableAdapter b = new BTableAdapter();
b.Insert(//some parameters); //step 2: throw exception
....
}
When running step 2, the program throws a exception and stop running the following functions,
but in database, there is a dummy record that generated in step 1,
how can i avoid that?
Wrap both steps in a Transaction.
See TransactionScope.
You will need to enlist the commands in the transaction.