Home All Groups Group Topic Archive Search About

get primary key on insert

Author
9 Mar 2006 9:48 PM
David Thielen
Hi;

If I have the primary key set to be created in the database, how can I get
it's value when I insert a new record in the database? Preferably a method
that works regardless of the vendor.

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com

Author
10 Mar 2006 3:25 AM
Kevin Yu [MSFT]
Hi Dave,

Is the primary key an autoincrement one? If so, you can add a SELECT
SCOPE_IDENTITY() statement in the insert command so that the value in the
DataTable can get refreshed. If you're using the DataAdapter wizard to
generate the SQL statements, you can check Refresh DataSet in the Advanced
options to achieve this.

You can check the following link for more information about SCOPT_IDENTITY()

http://msdn2.microsoft.com/en-us/library/ms190315.aspx

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
Author
10 Mar 2006 4:33 PM
Otis Mukinfus
On Fri, 10 Mar 2006 03:25:26 GMT, v-k***@online.microsoft.com (Kevin Yu [MSFT])
wrote:

Show quote
>Hi Dave,
>
>Is the primary key an autoincrement one? If so, you can add a SELECT
>SCOPE_IDENTITY() statement in the insert command so that the value in the
>DataTable can get refreshed. If you're using the DataAdapter wizard to
>generate the SQL statements, you can check Refresh DataSet in the Advanced
>options to achieve this.
>
>You can check the following link for more information about SCOPT_IDENTITY()
>
>http://msdn2.microsoft.com/en-us/library/ms190315.aspx
>
>Kevin Yu
>=======
>"This posting is provided "AS IS" with no warranties, and confers no
>rights."
There is no scope_identity() function in Oracle, which is another vendor.

Otis Mukinfus
http://www.arltex.com
http://www.tomchilders.com
Author
10 Mar 2006 8:38 AM
Cor Ligthert [MVP]
David,

Preferably a method that works regardless of the vendor.

AFAIK is that not there, even between Access (OleDB), SQLserver 2005
(SQLClient), SQLServer 2000  (SQLClient) are in this case differences while
the methods for SQLServer 2000 works as well on SQLServer 2005.

I hope this helps,

Cor
Author
10 Mar 2006 1:58 PM
David Thielen
yuck. Is there a list of how to do this for each DbConnection type somewhere?

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com



Show quote
"Cor Ligthert [MVP]" wrote:

> David,
>
>  Preferably a method that works regardless of the vendor.
>
> AFAIK is that not there, even between Access (OleDB), SQLserver 2005
> (SQLClient), SQLServer 2000  (SQLClient) are in this case differences while
> the methods for SQLServer 2000 works as well on SQLServer 2005.
>
> I hope this helps,
>
> Cor
>
>
>
Author
14 Mar 2006 5:21 AM
Kevin Yu [MSFT]
Hi dave,

I didn't find such method currently. This has a lot of dependencies on the
requirements and database. Let's wait and see if any community member can
shed some light on it.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
Author
16 Mar 2006 4:29 PM
Mary Chipman [MSFT]
Unfortunately there is no way to write truly provider-independent code
in ADO.NET 2.0 (or earlier). Another common roadblock is parameter
naming and placeholders. There is always going to be provider-specific
syntax that requires you to branch in your code or to write your own
framework (which some have done in order to support multiple
back-ends).

--Mary

On Tue, 14 Mar 2006 05:21:52 GMT, v-k***@online.microsoft.com (Kevin
Yu [MSFT]) wrote:

Show quote
>Hi dave,
>
>I didn't find such method currently. This has a lot of dependencies on the
>requirements and database. Let's wait and see if any community member can
>shed some light on it.
>
>Kevin Yu
>=======
>"This posting is provided "AS IS" with no warranties, and confers no
>rights."
Author
16 Mar 2006 5:54 PM
David Thielen
ok thanks - that's what I am doing. (Basically I'm implementing the JDBC API
on top of ADO.NET).

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com



Show quote
"Mary Chipman [MSFT]" wrote:

> Unfortunately there is no way to write truly provider-independent code
> in ADO.NET 2.0 (or earlier). Another common roadblock is parameter
> naming and placeholders. There is always going to be provider-specific
> syntax that requires you to branch in your code or to write your own
> framework (which some have done in order to support multiple
> back-ends).
>
> --Mary
>
> On Tue, 14 Mar 2006 05:21:52 GMT, v-k***@online.microsoft.com (Kevin
> Yu [MSFT]) wrote:
>
> >Hi dave,
> >
> >I didn't find such method currently. This has a lot of dependencies on the
> >requirements and database. Let's wait and see if any community member can
> >shed some light on it.
> >
> >Kevin Yu
> >=======
> >"This posting is provided "AS IS" with no warranties, and confers no
> >rights."
>
Author
20 Mar 2006 8:44 AM
Martin Aupperle
On Thu, 16 Mar 2006 11:29:51 -0500, "Mary Chipman [MSFT]"
<mc***@online.microsoft.com> wrote:

>Unfortunately there is no way to write truly provider-independent code
>in ADO.NET 2.0 (or earlier). Another common roadblock is parameter
>naming and placeholders. There is always going to be provider-specific
>syntax that requires you to branch in your code or to write your own
>framework (which some have done in order to support multiple
>back-ends).
>
OK, if we cannot write truly provider independent code for this, it
might be possible to show some code for the comonly used databases? In
this thread I learned how to do it with SQL-Server. Maybe someone can
show me how to do it with Oracle and  Access? Can we use stored
procedure to build an abstraction?

Greetings - Martin
Author
21 Mar 2006 12:26 AM
Mary Chipman [MSFT]
Here's the link to the docs for writing provider-independent code in
ADO.NET 2.0:
http://msdn2.microsoft.com/en-us/library/t9f29wbk(VS.80).aspx.

If you have additional questions, I'd recommend starting a new thread
so that you get the widest possible range of responses.

--Mary

On Mon, 20 Mar 2006 08:44:48 GMT, newsgro***@PrimaProgramm.de (Martin
Aupperle) wrote:

Show quote
>On Thu, 16 Mar 2006 11:29:51 -0500, "Mary Chipman [MSFT]"
><mc***@online.microsoft.com> wrote:
>
>>Unfortunately there is no way to write truly provider-independent code
>>in ADO.NET 2.0 (or earlier). Another common roadblock is parameter
>>naming and placeholders. There is always going to be provider-specific
>>syntax that requires you to branch in your code or to write your own
>>framework (which some have done in order to support multiple
>>back-ends).
>>
>OK, if we cannot write truly provider independent code for this, it
>might be possible to show some code for the comonly used databases? In
>this thread I learned how to do it with SQL-Server. Maybe someone can
>show me how to do it with Oracle and  Access? Can we use stored
>procedure to build an abstraction?
>
>Greetings - Martin
>
>
>
>
Author
21 Mar 2006 11:21 AM
Martin Aupperle
On Mon, 20 Mar 2006 16:26:34 -0800, "Mary Chipman [MSFT]"
<mc***@online.microsoft.com> wrote:

>Here's the link to the docs for writing provider-independent code in
>ADO.NET 2.0:
>http://msdn2.microsoft.com/en-us/library/t9f29wbk(VS.80).aspx.
>
I know this already, but thanks for the link anyway.
Unfortunately I do not see how this can help me with the problem.

The problem was: How can I get back to my program an auto generated
id-value when inserting a new record. Code for SQL-Server was given,
for Oracle and Access is still needed.


>If you have additional questions, I'd recommend starting a new thread
>so that you get the widest possible range of responses.
>
yes, thanks. But at the moment no additional questions. I would be
happy if someone can help me with the one I asked.

Greetings - Martin
Author
27 Mar 2006 7:40 PM
Mary Chipman [MSFT]
See http://msdn2.microsoft.com/en-us/library/ks9f57t0.aspx
("Retrieving Identity or Autonumber Values").

--Mary

On Tue, 21 Mar 2006 11:21:54 GMT, newsgro***@PrimaProgramm.de (Martin
Aupperle) wrote:

Show quote
>On Mon, 20 Mar 2006 16:26:34 -0800, "Mary Chipman [MSFT]"
><mc***@online.microsoft.com> wrote:
>
>>Here's the link to the docs for writing provider-independent code in
>>ADO.NET 2.0:
>>http://msdn2.microsoft.com/en-us/library/t9f29wbk(VS.80).aspx.
>>
>I know this already, but thanks for the link anyway.
>Unfortunately I do not see how this can help me with the problem.
>
>The problem was: How can I get back to my program an auto generated
>id-value when inserting a new record. Code for SQL-Server was given,
>for Oracle and Access is still needed.
>
>
>>If you have additional questions, I'd recommend starting a new thread
>>so that you get the widest possible range of responses.
>>
>yes, thanks. But at the moment no additional questions. I would be
>happy if someone can help me with the one I asked.
>
>Greetings - Martin

AddThis Social Bookmark Button