Click here to Skip to main content
15,914,795 members
Home / Discussions / C#
   

C#

 
QuestionTableAdapter and Transactions. [modified] Pin
hdv2123-Mar-09 5:50
hdv2123-Mar-09 5:50 
Hi I want to use Transactions with TableAdapter class which visual studio dataset designer create for each database objects (tables,...).
i found this article to do this : http://blah.winsmarts.com/2006/06/18/the-definitive-tableadapters--transactions-blog-post.aspx[^]

now u can use transactional tableAdapter like this :
CustomersTableAdapter tableAdap = new CustomersTableAdapter() ;
SqlTransaction tableAdapTran = null ;
SqlConnection tableAdapConn = null ;

try
{
    tableAdapConn = tableAdap.OpenConnection() ;
    tableAdapTran = tableAdapConn.BeginTransaction() ;

    // Do your transactional work

    tableAdapTran.Commit() ;
}
catch (Exception)
{
    tableAdapTran.Rollback() ;
}
finally
{
    tableAdapConn.Close() ;
}

this works fine when u want working with a one TableAdapter. for multuple tableAdapters, u need extend each tableAdapter class for supporting Transactional operation.
In my scenario : i'm dealing with multiple tables (insert,update or delete to/from multiple tables) within a single transaction and i think above method does not correct for this operation. look at this code sample :

CustomersTableAdapter tableAdap = new CustomersTableAdapter() ;
SqlTransaction tableAdapTran = null;
SqlConnection tableAdapConn = null;

OrdersTableAdapter ordersAdapter = new OrdersTableAdapter();
SqlTransaction ordersAdapterTran = null;
SqlConnection ordersAdapterConn = null;

try
{
    tableAdapConn = tableAdap.OpenConnection();
    tableAdapTran = tableAdapConn.BeginTransaction();

    ordersAdapterConn = ordersAdapter.OpenConnection();
    ordersAdapterTran = ordersAdapterConn.BeginTransaction();


    // What i must write here ?


    tableAdapTran.Commit();
}
catch (Exception)
{
    tableAdapTran.Rollback();
}
finally
{
    tableAdapConn.Close();
}


can anybody help me about this issue ?
Note : i don't want to use TransactionScope class.
thanks

modified on Tuesday, March 3, 2009 11:56 AM

QuestionError Loading type during runtime Pin
Mustafa Ismail Mustafa3-Mar-09 3:45
Mustafa Ismail Mustafa3-Mar-09 3:45 
AnswerRe: Error Loading type during runtime Pin
Eddy Vluggen3-Mar-09 3:55
professionalEddy Vluggen3-Mar-09 3:55 
GeneralRe: Error Loading type during runtime Pin
Mustafa Ismail Mustafa3-Mar-09 3:59
Mustafa Ismail Mustafa3-Mar-09 3:59 
GeneralRe: Error Loading type during runtime Pin
Eddy Vluggen3-Mar-09 4:10
professionalEddy Vluggen3-Mar-09 4:10 
GeneralRe: Error Loading type during runtime Pin
Mustafa Ismail Mustafa3-Mar-09 4:11
Mustafa Ismail Mustafa3-Mar-09 4:11 
AnswerRe: Error Loading type during runtime Pin
J4amieC3-Mar-09 4:31
J4amieC3-Mar-09 4:31 
GeneralRe: Error Loading type during runtime Pin
Mustafa Ismail Mustafa3-Mar-09 4:38
Mustafa Ismail Mustafa3-Mar-09 4:38 
AnswerRe: Error Loading type during runtime Pin
Yusuf3-Mar-09 4:36
Yusuf3-Mar-09 4:36 
GeneralRe: Error Loading type during runtime Pin
Mustafa Ismail Mustafa3-Mar-09 4:39
Mustafa Ismail Mustafa3-Mar-09 4:39 
GeneralRe: Error Loading type during runtime Pin
Yusuf3-Mar-09 4:49
Yusuf3-Mar-09 4:49 
GeneralRe: Error Loading type during runtime Pin
Mustafa Ismail Mustafa3-Mar-09 4:52
Mustafa Ismail Mustafa3-Mar-09 4:52 
AnswerRe: Error Loading type during runtime Pin
Mustafa Ismail Mustafa3-Mar-09 4:55
Mustafa Ismail Mustafa3-Mar-09 4:55 
GeneralRe: Error Loading type during runtime Pin
Yusuf3-Mar-09 5:02
Yusuf3-Mar-09 5:02 
QuestionPanel Event Pin
Cliffer3-Mar-09 3:13
Cliffer3-Mar-09 3:13 
AnswerRe: Panel Event Pin
Calin Tatar3-Mar-09 3:34
Calin Tatar3-Mar-09 3:34 
GeneralRe: Panel Event [modified] Pin
Megidolaon4-Mar-09 2:30
Megidolaon4-Mar-09 2:30 
QuestionOdd Referencing Problem Pin
Jammer3-Mar-09 1:55
Jammer3-Mar-09 1:55 
AnswerRe: Odd Referencing Problem Pin
ABitSmart3-Mar-09 3:15
ABitSmart3-Mar-09 3:15 
GeneralRe: Odd Referencing Problem Pin
Jammer3-Mar-09 3:18
Jammer3-Mar-09 3:18 
AnswerRe: Odd Referencing Problem Pin
led mike3-Mar-09 4:20
led mike3-Mar-09 4:20 
GeneralRe: Odd Referencing Problem Pin
Jammer3-Mar-09 5:11
Jammer3-Mar-09 5:11 
Questionc# and XML validation [modified] Pin
mocasu3-Mar-09 0:51
mocasu3-Mar-09 0:51 
AnswerRe: c# and XML validation Pin
Greg Chelstowski3-Mar-09 3:29
Greg Chelstowski3-Mar-09 3:29 
GeneralRe: c# and XML validation Pin
mocasu3-Mar-09 4:55
mocasu3-Mar-09 4:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.