Click here to Skip to main content
15,923,164 members
Home / Discussions / C#
   

C#

 
GeneralRe: unit testing function Pin
SeMartens29-Apr-09 21:09
SeMartens29-Apr-09 21:09 
QuestionCapture network Video stream? Pin
IvanBeograd28-Apr-09 20:03
IvanBeograd28-Apr-09 20:03 
AnswerRe: Capture network Video stream? Pin
IvanBeograd5-May-09 14:10
IvanBeograd5-May-09 14:10 
QuestionNot able to receive data using tcp(urgent!) Pin
patra.santanu@yahoo.co.in28-Apr-09 19:56
patra.santanu@yahoo.co.in28-Apr-09 19:56 
Questionsave gridview values in database Pin
grkrishna28-Apr-09 19:10
grkrishna28-Apr-09 19:10 
AnswerRe: save gridview values in database PinPopular
grkrishna28-Apr-09 22:26
grkrishna28-Apr-09 22:26 
AnswerRe: save gridview values in database [modified] Pin
sorifazlu14-Sep-11 23:26
sorifazlu14-Sep-11 23:26 
Questionfind .lib, .dll in exe Pin
RKP72828-Apr-09 19:05
RKP72828-Apr-09 19:05 
AnswerRe: find .lib, .dll in exe Pin
RKP72828-Apr-09 19:06
RKP72828-Apr-09 19:06 
QuestionHow can I get the time taken for PDF getting downloaded when it is opened on Internet Explorer? Pin
svt gdwl28-Apr-09 18:19
svt gdwl28-Apr-09 18:19 
AnswerRe: How can I get the time taken for PDF getting downloaded when it is opened on Internet Explorer? Pin
_Maxxx_28-Apr-09 19:45
professional_Maxxx_28-Apr-09 19:45 
QuestionUnable to load DLL - Why ?? Pin
matty2desmara28-Apr-09 15:53
matty2desmara28-Apr-09 15:53 
AnswerRe: Unable to load DLL - Why ?? Pin
Luc Pattyn28-Apr-09 16:31
sitebuilderLuc Pattyn28-Apr-09 16:31 
GeneralRe: Unable to load DLL - Why ?? Pin
matty2desmara29-Apr-09 4:08
matty2desmara29-Apr-09 4:08 
AnswerRe: Unable to load DLL - Why ?? Pin
jas0n2328-Apr-09 23:27
jas0n2328-Apr-09 23:27 
GeneralRe: Unable to load DLL - Why ?? Pin
matty2desmara29-Apr-09 4:20
matty2desmara29-Apr-09 4:20 
AnswerRe: Unable to load DLL - Why ?? Pin
matty2desmara29-Apr-09 4:54
matty2desmara29-Apr-09 4:54 
AnswerRe: Unable to load DLL - Why ?? Pin
S. Senthil Kumar30-Apr-09 9:53
S. Senthil Kumar30-Apr-09 9:53 
QuestionDrag drop from picturebox to desktop? Pin
Jacob Dixon28-Apr-09 13:32
Jacob Dixon28-Apr-09 13:32 
GeneralRate this tricky code : Use multiple TableAdapters within a single transaction! Pin
hdv21228-Apr-09 9:29
hdv21228-Apr-09 9:29 
Hi everybody
after a lot of weeks about update related tables in database in a single transaction and configuring TableAdapters with stored procedures for CRUD operations, and having many trouble with TableAdapterManager.UpdateAll method to do this (see this post), i decide write some tricky code to do this myself and i put this code here for discussion :

Note : i have 2 tables, Customers & Orders. The Customers table is a parent of Orders table



TestDataSet ds = new TestDataSet();

private void toolStripButton1_Click(object sender, EventArgs e)
{            
            if (ds.Customers.GetChanges() != null || ds.Orders.GetChanges() != null)
            {
                using (SqlConnection con = new SqlConnection(Properties.Settings.Default.TestConnectionString))
                {
                    SqlTransaction tr = null;
                    try
                    {
                        if (con.State != ConnectionState.Open)
                            con.Open();
                        tr = con.BeginTransaction();
                        if (ds.Customers.GetChanges() != null)
                        {
                            TestDataSetTableAdapters.CustomersTableAdapter customersAdapter = new TransactionalUpdate.TestDataSetTableAdapters.CustomersTableAdapter();
                       
                            // Set connection and transaction of TableAdapter to current connection and transaction (con,tr)
                            customersAdapter.Connection = con;
                            customersAdapter.Adapter.InsertCommand.Transaction
                            = customersAdapter.Adapter.UpdateCommand.Transaction
                            = customersAdapter.Adapter.DeleteCommand.Transaction = tr;
                            customersAdapter.Update(ds.Customers.GetChanges() as TestDataSet.CustomersDataTable);
                        }
                        if (ds.Orders.GetChanges() != null)
                        {
                            TestDataSetTableAdapters.OrdersTableAdapter ordersAdapter = new TransactionalUpdate.TestDataSetTableAdapters.OrdersTableAdapter();
                        
                            // Set connection and transaction of TableAdapter to current connection and transaction (con,tr)
                            ordersAdapter.Connection = con;
                            ordersAdapter.Adapter.InsertCommand.Transaction
                            = ordersAdapter.Adapter.UpdateCommand.Transaction
                            = ordersAdapter.Adapter.DeleteCommand.Transaction
                            = ordersAdapter.Adapter.DeleteCommand.Transaction = tr;
                            ordersAdapter.Update(ds.Orders as TestDataSet.OrdersDataTable);
                        }
                        ds.Customers.AcceptChanges();
                        ds.Orders.AcceptChanges();
                        tr.Commit();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                        tr.Rollback();
                    }
                    finally
                    {
                        if (con.State != ConnectionState.Closed)
                            con.Close();
                    }
                }
            }
}


what about u ?
Is this code good ?
do u have idea to optimize this code ?
Thanks.
GeneralRe: Rate this tricky code : Use multiple TableAdapters within a single transaction! Pin
Henry Minute28-Apr-09 10:49
Henry Minute28-Apr-09 10:49 
GeneralRe: Rate this tricky code : Use multiple TableAdapters within a single transaction! Pin
hdv21228-Apr-09 11:51
hdv21228-Apr-09 11:51 
QuestionReading a Konica Minolta printer to get print & copy counts Pin
crazylad28-Apr-09 9:19
crazylad28-Apr-09 9:19 
AnswerRe: Reading a Konica Minolta printer to get print & copy counts Pin
Henry Minute28-Apr-09 10:51
Henry Minute28-Apr-09 10:51 
GeneralRe: Reading a Konica Minolta printer to get print & copy counts Pin
crazylad6-May-09 5:08
crazylad6-May-09 5:08 

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.