473,395 Members | 2,468 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Save several DataTables of DataSet

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
May 10 '07 #1
6 4104
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.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Joe Kovac" <Jo****@nospam.comwrote in message
news:33***************************@news.inode.at.. .
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

May 10 '07 #2
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

Nicholas Paldino [.NET/C# MVP] wrote:
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.

May 11 '07 #3
Joe,

See inline:
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?
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.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

>
The journey is the reward.

Joe

Nicholas Paldino [.NET/C# MVP] wrote:
>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.
May 11 '07 #4
Nicholas Paldino [.NET/C# MVP] wrote:
Joe,

See inline:
>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?

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).
Well, I tried to handle the transactions myself. I followed the template
provided at:

http://weblogs.asp.net/ryanw/archive...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
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.

May 14 '07 #5
Joe Kovac wrote:
Nicholas Paldino [.NET/C# MVP] wrote:
>Joe,

See inline:
>>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?

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).

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

http://weblogs.asp.net/ryanw/archive...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?)
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
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.

May 14 '07 #6
>> 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).

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

http://weblogs.asp.net/ryanw/archive...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?)

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?
Anyone???
May 16 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: William Ryan | last post by:
At the risk of sounding like a Big 5 consultant, "It depends". 1) Strongly typed datasets rock, they are faster than untyped, use intellisense... but your reason for wanting to use them is...
2
by: Jade | last post by:
Hi, I just wanted to ask a quick question regarding datasets. I am creating 3 tables using a dataadapter. what i want to know is that is the relationship created between these datatables...
2
by: Z D | last post by:
Hello, I'm currently using Remoting (HTTP/Binary) to remote a simple object. Everything is working fine except for one function that returns an arraylist of datatables. When I call this...
2
by: Alpha | last post by:
Hi, I have a window based program. One of the form has several textboxes and a datagrid. The textboxes are bind to the same dataset table as the datagrid and the text changes to reflect different...
4
by: sal | last post by:
Greets, All Converting array formula to work with datatables/dataset tia sal I finally completed a formula I was working on, see working code below. I would like to change this code so it...
3
by: cj | last post by:
I've used datatables and datasets before. Datasets being able to hold more than one table and datatables being only one table. My mind keeps coming up with recordsets. I can't remember how they...
2
by: Michael D. Reed | last post by:
I have 2 list boxes and a combo box that are bound to table adaptors. I have another table that has relations with the underlying tables to the adaptors above. I have set this up in a dataset. ...
1
by: =?ISO-8859-1?Q?Mika=EBl_PLOUHINEC?= | last post by:
Hello, I have a dataset with 2 DataTables : Groups and Persons. I make a relation between this 2 DataTables using one DataColumn in each datatable. Finally I use this dataset in a dataGrid. So I...
0
by: StefanPienaar | last post by:
Hi Guys Is there any way in c# (or vb.net) to extract a datatable of data from a dataset with multiple datatables which has relationships set up (containing combined data from the datatables)? ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.