So this is the problem.
I need to insert into tableA and get its new row id. After that, I must insert that id into tableB. I must commit after the insert into tableA so that when I attempt to insert into tableB I won't get a foreign key exception.
Now, my understanding was that if an exception was raised in the function that inserts into tableB, when the try-catch block catches the exception the original insertion into the table would be rollbacked. It isn't doing that.
I am making a mistake somewhere, but I don't know where. Is there a way to accomplish what I need here?
try
{
tableAinsert.ExecuteNonQuery();
transaction.Commit();
id= Int32.Parse(tableAinsert.Parameters["id"].Value.ToString());
if (vsType == "I")
{
tableBinsert(vsType, eventId, id);
}
}
catch (Exception err)
{
transaction.Rollback();
throw (err);
}