Sahil
Wed Jun 08 11:42:50 CDT 2005
Answer to #1 ---
Slightly. Yes :-) (or should I put this smiley :-( ? ;) ).
Well, it will be slightly worse than a batched update in .NET 2.0. In .NET
1.1 it'll be just as good/bad.
Answer to #2 ---
Yes it has to be the same transaction AND connection object. What you could
do however is that you could segregate the connection and transaction object
to only a logical grouping of rows - rather than the whole hierarchical
table structure. If your architecture permits - that frankly would be a
kickass choice in comparison. This way you would lock the fewest rows. BTW -
I would strongly recommend that you go in row states - row groups in one
transaction rather than all the table, all rows, all row states in one
transaction.
- Sahil Malik [MVP]
Upcoming ADO.NET 2.0 book -
http://tinyurl.com/9bync
----------------------------------------------------------------------------
---------------
"NewBie" <NewBie@discussions.microsoft.com> wrote in message
news:48CCD65C-C6B0-475B-811D-DAE39EA312A4@microsoft.com...
> Hi Sahil,
>
> your post is really good, however i have a few queries.....
>
> 1)In the below code block, does the ADO internals work in an inefficient
> way.. i.e
> first of all the inserted records will be inserted by calling the insert
> stored procs(as per teh command object)......
> and then for the same inserted rows which had a couple of fields updated
an
> update stored proc will be run? Is this not inefficient work by the ADO by
> making an extra call to the db for the updates?
>
>
> 2)In the below code example, does the connection has to be the same for
both
> the master and transaction tables?
> Can just the idbtransaction be used to be passed around?
> This is because the way my classes and methods are defined, the connection
> woulld be pooled and the updates for the master and transaction tables
from
> the UI may be in a separate state and the code is modular so that the
> connection object obtained may differ at each time and transaction based
> details are kept transparent from the data layer (besides the information
> about the transaction through IDBtransaction).
>
> I hope i was clear to explain my queries..
>
> Appreciate your response on the same.
>
> Thanks.
>
>
>
> "Sahil Malik [MVP]" wrote:
>
> > Okay now that the problem is in my head. :)
> >
> > The approach really doesn't change much even in this case, but it does
> > depend on your final database structure.
> >
> > So if Group were to be saved in a table, and groupdetails in another,
you'd
> > have to call ExecuteNonQuery instead of DataAdapter.Update for Group,
and
> > Datadapter.Update(DataRow[]) for the GroupDetails table.
> >
> > The basic concept remains the same.
> > Group Insert
> > Group Update
> >
> > GroupDetail Insert
> > GroupDetail Update
> >
> > ... Just remember, contrary to MSDN docs, DataAdapter.Update(dataSet)
doesn't
> > really call the commands on EACH row in the dataset. Only in the first
> > datatable, or the datatable identified by the name "Table".
> >
> > To wrap it all up in a transaction,
> >
> > Do a
> >
> > connection.open
> > tran = conn.BeginTransaction
> > cmd.transaction = tran
> > cmd.executenonquery
> > cmd2.transaction = tran
> > datadapter.insertcommand = cmd2
> > datarow[] insertedrows =
> > groupdetailsdatatable.select("","",DataRowState.Added)
> > dataadapter.Update(insertedrows);
> > /// other such commands
> > tran.commit
> > conn.close
> >
> > I wish I could hand you a copy of my next book with a working example of
> > this in Chapter #10, but that doesn't come till September. I know it
isn't
> > quite as straightforward as you'd like it to, but you do have to go
through
> > all the hoops.
> >
> > Did I mention one more detail - If a new Group is inserted, then you
willl
> > have to retreive the right key values to put in GroupDetails. Now
inserting
> > a Group can be into one table, or sixty tables - any SQL will do, but if
> > there is a foreign key association, you will definitely need to do that.
> >
> > The EXACT answer depends on your DB structure. But the concepts are
still
> > the same.
> >
> > - Sahil Malik [MVP]
> >
http://codebetter.com/blogs/sahil.malik/
> >
> >
> >
> >
> > <gwolinsky@millermartin.com> wrote in message
> > news:1112647615.725996.64160@o13g2000cwo.googlegroups.com...
> > > That's it. I'm sorry if wasn't very clear the first time. :-)
> > >
> > > Thanks,
> > > Glen
> > >
> >
> >