PC Review


Reply
Thread Tools Rate Thread

Datasets and identities in ADO.NET 2.0

 
 
Massimo
Guest
Posts: n/a
 
      22nd Jun 2005
Hi to all, I'm developing a test application with Visual Studio 2005 Beta 2
and the 2.0 framework (along as SQL Server 2005 June CTP), and I'd like to
know if they introduce some improvements in order to solve an old problem:
how to deal with inserting values from a DataSet into two related tables
when one of them has an auto-generated ID column.

Let's say I have these two tables in the DB, Table1 and Table2, and Table1
has an "ID" column which is configured as an auto-generating identity;
Table2 also has an ID column, which references Table1.ID in a foreign key
relation.

Now, I'm loading these two tables in a typed DataSet, which, being typed,
knows the structure of the tables and the relation between them; I put a new
row into Table1, and then another one in Table2 referencing the new
Table1.ID.

The question is: how do I put those new data into the DB, since I can't
specify the value of the column in the master table?

I know there are some workarounds for this problem (like retrieving the new
auto-generated ID and storing it in the DataSet, or using stored procedures
to update the tables, or using placeholder values in the DataSet before
submitting the changes, or using GUIDS), but I'd like to know if ADO.NET 2.0
solves this problem in a more elegant way than 1.0 and 1.1 did; the new
framework has so many improvements... this one would be quite helpful.

Thanks for any answer.


Massimo

 
Reply With Quote
 
 
 
 
Cor Ligthert
Guest
Posts: n/a
 
      22nd Jun 2005
Massimo,

Beta2 is not a released product. For testing is it much appriciated when you
use these newsgroups

http://lab.msdn.microsoft.com/vs2005/community/

I hope this helps,

Cor


 
Reply With Quote
 
Miha Markic [MVP C#]
Guest
Posts: n/a
 
      22nd Jun 2005
Hi Massimo,

No, the idea is still the same and AFAIK it is a good solution.
You just save the rows in proper order and upon successful save you retrieve
auto generated ids.
DataRelations will take care of updating the ids in DataSet.

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/
SLODUG - Slovene Developer Users Group www.codezone-si.info

"Massimo" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi to all, I'm developing a test application with Visual Studio 2005 Beta
> 2 and the 2.0 framework (along as SQL Server 2005 June CTP), and I'd like
> to know if they introduce some improvements in order to solve an old
> problem: how to deal with inserting values from a DataSet into two related
> tables when one of them has an auto-generated ID column.
>
> Let's say I have these two tables in the DB, Table1 and Table2, and Table1
> has an "ID" column which is configured as an auto-generating identity;
> Table2 also has an ID column, which references Table1.ID in a foreign key
> relation.
>
> Now, I'm loading these two tables in a typed DataSet, which, being typed,
> knows the structure of the tables and the relation between them; I put a
> new row into Table1, and then another one in Table2 referencing the new
> Table1.ID.
>
> The question is: how do I put those new data into the DB, since I can't
> specify the value of the column in the master table?
>
> I know there are some workarounds for this problem (like retrieving the
> new auto-generated ID and storing it in the DataSet, or using stored
> procedures to update the tables, or using placeholder values in the
> DataSet before submitting the changes, or using GUIDS), but I'd like to
> know if ADO.NET 2.0 solves this problem in a more elegant way than 1.0 and
> 1.1 did; the new framework has so many improvements... this one would be
> quite helpful.
>
> Thanks for any answer.
>
>
> Massimo
>



 
Reply With Quote
 
Sahil Malik [MVP]
Guest
Posts: n/a
 
      22nd Jun 2005
Your answer is right here -
http://codebetter.com/blogs/sahil.ma.../06/62893.aspx


--

- Sahil Malik [MVP]
Upcoming ADO.NET 2.0 book - http://tinyurl.com/9bync
----------------------------------------------------------------------------

"Massimo" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi to all, I'm developing a test application with Visual Studio 2005 Beta
> 2 and the 2.0 framework (along as SQL Server 2005 June CTP), and I'd like
> to know if they introduce some improvements in order to solve an old
> problem: how to deal with inserting values from a DataSet into two related
> tables when one of them has an auto-generated ID column.
>
> Let's say I have these two tables in the DB, Table1 and Table2, and Table1
> has an "ID" column which is configured as an auto-generating identity;
> Table2 also has an ID column, which references Table1.ID in a foreign key
> relation.
>
> Now, I'm loading these two tables in a typed DataSet, which, being typed,
> knows the structure of the tables and the relation between them; I put a
> new row into Table1, and then another one in Table2 referencing the new
> Table1.ID.
>
> The question is: how do I put those new data into the DB, since I can't
> specify the value of the column in the master table?
>
> I know there are some workarounds for this problem (like retrieving the
> new auto-generated ID and storing it in the DataSet, or using stored
> procedures to update the tables, or using placeholder values in the
> DataSet before submitting the changes, or using GUIDS), but I'd like to
> know if ADO.NET 2.0 solves this problem in a more elegant way than 1.0 and
> 1.1 did; the new framework has so many improvements... this one would be
> quite helpful.
>
> Thanks for any answer.
>
>
> Massimo
>



 
Reply With Quote
 
Massimo
Guest
Posts: n/a
 
      23rd Jun 2005
"Massimo" <(E-Mail Removed)> ha scritto nel messaggio
news:(E-Mail Removed)...

> I'd like to know if ADO.NET 2.0 solves this problem


Well, it seems the framework doesn't solve the problem by itself, but Visual
Studio does (at least the 2005 version, I don't know how 2002/2003 handles
this); when creating the insert and update commands, if you select the
"refresh dataset" option, it notes the column is an ID and builds the select
query to retrieve the modified row using @@IDENTITY.

Now, another little question: when creating a typed DataSet in Visual Studio
2005, the relations are set by default to not cascade updates, *even if they
are cascading in the DB*. So, when adding some tables and relations to a
DataSet, I need to manually configure each one of them. Is this by design,
or is it a bug of the beta version that I should report to the developers?
Shouldn't the IDE create cascading or non-cascading relations based on how
the DB handles them?

Massimo

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do Datasets manage to get deserialized as DataSets instead of a wsdl.exe-created proxy class? Francisco Garcia Microsoft ASP .NET 2 13th Apr 2006 11:41 AM
How do Datasets manage to get deserialized as DataSets instead of a wsdl.exe-created proxy class? news.microsoft.com Microsoft ASP .NET 0 12th Apr 2006 10:07 AM
Discussion: Typet DataSets vs Untyped DataSets Przemo Microsoft VB .NET 11 3rd Sep 2004 07:58 AM
Typed DataSets returned as regular datasets =?Utf-8?B?Sm9uIEtpbmc=?= Microsoft ADO .NET 2 29th Aug 2004 01:41 AM
Converting Untyped Datasets into Strongly Typed Datasets with Foreign Key Constraints. Alex Berryhill Microsoft ADO .NET 2 19th Mar 2004 02:20 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:14 PM.