Home All Groups Group Topic Archive Search About

Best way to get the identity for new records?

Author
5 May 2007 2:23 PM
Brooke
I am helping develop a SQL Server 2005 application with a C# front-end.
Originally I was using untyped datasets and stored procedures and it worked
fine.  Now I have been told to used typed datasets and table adapters.  How
do I get the identity for new rerecords?  Is it a good idea to use typed
datasets on a database with about 25 tables?

The issue is that I have multiple datagrids that are dependant on each other
and are linked with foreign keys.  When I save the records I start with the
highest level form and work my way down on the inserts.  The identity is not
generated until the records is written to the db, but I need the identity
for the following child tables.

Thanks

Author
7 May 2007 11:48 PM
Earl
I use typed datasets on a database with over 200 tables. It is irrelevant,
because you probably aren't going to create one massive dataset, you are
going to create one dataset for each form. So your datasets will have
typically a handful of tables. If you set your autonumber seed to -1 and
increment to -1, then you can discern your new records by their negative
values. If you use stored procedures, look at the table visualizer once you
have submitted your insert; you should see the newly generated PK out of the
parent tables.

Show quote
"Brooke" <tbroo***@hotmail.com> wrote in message
news:eTQhrDyjHHA.4032@TK2MSFTNGP02.phx.gbl...
>I am helping develop a SQL Server 2005 application with a C# front-end.
>Originally I was using untyped datasets and stored procedures and it worked
>fine.  Now I have been told to used typed datasets and table adapters.  How
>do I get the identity for new rerecords?  Is it a good idea to use typed
>datasets on a database with about 25 tables?
>
> The issue is that I have multiple datagrids that are dependant on each
> other and are linked with foreign keys.  When I save the records I start
> with the highest level form and work my way down on the inserts.  The
> identity is not generated until the records is written to the db, but I
> need the identity for the following child tables.
>
> Thanks
>

AddThis Social Bookmark Button