Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / May 2007

Tip: Looking for answers? Try searching our database.

Save several DataTables of DataSet

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Joe Kovac - 10 May 2007 13:05 GMT
Hi!

I change quite a lot TableRows in several Tables of a typed DataSet. Now
I would like to know which is the best way to save all the rows.

Currently I just use each TableAdapters Update() method.
First, I think I should have some kind of transactions.
Secondly, I think I should use GetChanges()?

Where can I get more informations on how to save the data best? Most
samples are for non typed DataSets and I think it shouldn't be so hard
with a typed DataSet.

Any good samples?

Thanks

Joe
Nicholas Paldino [.NET/C# MVP] - 10 May 2007 15:42 GMT
Joe,

   If you have a sample that doesn't use a typed data set, then you can use
it with a typed data set, since typed data sets derive from untyped data
sets.

   Generally, you are going to use DataAdapter classes to perform the
updates.  If you used the designer to generate your data sets from tables in
a database, then it should have created classes that end in TableAdapter as
well which you can use to save the various records in the typed data set.

   If you need transactions, then you should look into the TransactionScope
class in the System.Transactions namespace.  You can wrap your code in a
using statment with an instance of the TransactionScope class and it will
place all operations in that code block in a Transaction.

   Hope this helps.

Signature

         - Nicholas Paldino [.NET/C# MVP]
         - mvp@spam.guard.caspershouse.com

> Hi!
>
[quoted text clipped - 14 lines]
>
> Joe
Joe Kovac - 11 May 2007 06:51 GMT
Thanks for your information.

I tried:

using (TransactionScope ts = new TransactionScope())
{
    mds.UpdateTable1();
    mds.UpdateTable2();
    mds.UpdateTable3();
}

And got:

The transaction manager has disabled its support for remote/network
transactions.

Without the TransactionScope it worked fine. But the TransactionScope
causes the error above. I guess I have to change some settings on the
server, haven't I? Which ones and where?
Would this also work with non MS-SQl 2005 servers?

Do I have other possibilities? E.g. creating a new delta DataSet using
getChanges() and putting another connection into it? But how would I do
that?

And what is getChanges() good for in general? Wouldn't a Table.Update()
automatically "call" getChanges() and just update the modified rows?

The journey is the reward.

Joe

> Joe,
>
[quoted text clipped - 13 lines]
>
>     Hope this helps.
Nicholas Paldino [.NET/C# MVP] - 11 May 2007 19:06 GMT
Joe,

   See inline:

> The transaction manager has disabled its support for remote/network
> transactions.
[quoted text clipped - 3 lines]
> server, haven't I? Which ones and where?
> Would this also work with non MS-SQl 2005 servers?

   Without TransactionScope, it worked, but if you had an error on the
second update, none of the work would be rolled back.  The
TransactionManager would most likely not work with non MS SQL Server 2005
installations since you would have to have DTC running on both machines to
handle the coordination of the distributed transaction.

> Do I have other possibilities? E.g. creating a new delta DataSet using
> getChanges() and putting another connection into it? But how would I do
> that?

   You could manage the transaction yourself, by calling BeginTransaction
on the connection.  However, depending on your needs for transaction based
processing, this can get very unwieldy very quickly (especially if you have
multiple calls you need to handle in the transaction, you would have to pass
the transaction object everywhere).

   GetChanges is only going to give you the changes that occured in the
datatable, nothing more.  Using another connection to process it isn't going
to help.

> And what is getChanges() good for in general? Wouldn't a Table.Update()
> automatically "call" getChanges() and just update the modified rows?

   The Update method on the DataAdapter is going to cycle through the rows
and if there is a changed state for a row, it is going to process it.
However, AFAIK, it does not call GetChanges to only get changed rows.

Signature

         - Nicholas Paldino [.NET/C# MVP]
         - mvp@spam.guard.caspershouse.com

> The journey is the reward.
>
[quoted text clipped - 19 lines]
>>
>>     Hope this helps.
Joe Kovac - 14 May 2007 07:17 GMT
> Joe,
>
[quoted text clipped - 23 lines]
> multiple calls you need to handle in the transaction, you would have to pass
> the transaction object everywhere).

Well, I tried to handle the transactions myself. I followed the template
provided at:

http://weblogs.asp.net/ryanw/archive/2006/03/30/441529.aspx

Unfortunately I got following error:

"ExecuteReader requires the command to have a transaction when the
connection assigned to the command is in a pending local transaction.
The Transaction property of the command has not been initialized."

How can I fix that? (Or is there another easy way to implement
transactions within datasets without DTC?)

>     GetChanges is only going to give you the changes that occured in the
> datatable, nothing more.  Using another connection to process it isn't going
[quoted text clipped - 6 lines]
> and if there is a changed state for a row, it is going to process it.
> However, AFAIK, it does not call GetChanges to only get changed rows.
Joe Kovac - 14 May 2007 08:39 GMT
>> Joe,
>>
[quoted text clipped - 38 lines]
> How can I fix that? (Or is there another easy way to implement
> transactions within datasets without DTC?)

According to another news group entry it might never be possible to use
a transaction by hand:

# "Figured it out.  The TableAdapterHelper sets all the commands
# transactions... but the .Update() command doesn't use an existing
# command, it dynamically builds one.  This, of course, means that the
# transaction is not set on that command.  So I'm using manual SQL
# statements instead of Update. "

If I am (hopefully!) wrong, how to do the transaction handling exactly?

>>     GetChanges is only going to give you the changes that occured in
>> the datatable, nothing more.  Using another connection to process it
[quoted text clipped - 7 lines]
>> rows and if there is a changed state for a row, it is going to process
>> it. However, AFAIK, it does not call GetChanges to only get changed rows.
Joe Kovac - 16 May 2007 06:30 GMT
>>>     You could manage the transaction yourself, by calling
>>> BeginTransaction on the connection.  However, depending on your needs
[quoted text clipped - 27 lines]
>
> If I am (hopefully!) wrong, how to do the transaction handling exactly?

Anyone???

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.