Wrox Home  
Search P2P Archive for: Go

  Return to Index  

ado_dotnet thread: ADO.Net & Identity Seed fields


Message #1 by "Dave Buckner" <Dave@N...> on Mon, 18 Mar 2002 09:28:02 -0600
Hey everyone,

Does anyone have a idea of how I can return a identity field after updating
the data adapter when adding a new row to a table in a dataset? Here is a
VB6 example of what I mean....

with aUDT
    rsRecordset.Fields("aField").value = .aField
    rsRecordset.Update
    If .IsNew Then
      rsRecordset.Bookmark = rsRecordset.Bookmark
      .ID = rsRecordset("ID")
    End If
End With

Thanks,
Dave


Message #2 by "Terry Carr" <Terry.Carr@r...> on Mon, 18 Mar 2002 10:42:59 -0500
Dave,

If you are using SQL Server (or Oracle, but its slightly different there -
I'm assuming SQL Server since you called it an identity) you should perform
your insert in a stored procedure and return the new id using RETURN
@@IDENTITY

----- Original Message -----
From: "Dave Buckner" <Dave@N...>
To: "ADO.NET" <ado_dotnet@p...>
Sent: Monday, March 18, 2002 10:28 AM
Subject: [ado_dotnet] ADO.Net & Identity Seed fields


> Hey everyone,
>
> Does anyone have a idea of how I can return a identity field after
updating
> the data adapter when adding a new row to a table in a dataset? Here is a
> VB6 example of what I mean....
>
> with aUDT
>     rsRecordset.Fields("aField").value = .aField
>     rsRecordset.Update
>     If .IsNew Then
>       rsRecordset.Bookmark = rsRecordset.Bookmark
>       .ID = rsRecordset("ID")
>     End If
> End With
>
> Thanks,
> Dave
>
>
>
>

Message #3 by "Dave Buckner" <Dave@N...> on Tue, 19 Mar 2002 11:08:59 -0600
Terry,

Thanks for the response! I am using SQL Server. That's not a bad idea, I do
wonder about ntext fields though. Any suggestions on these?

Thanks alot!
Dave

-----Original Message-----
From: Terry Carr [mailto:Terry.Carr@r...]
Sent: Monday, March 18, 2002 9:43 AM
To: ADO.NET
Subject: [ado_dotnet] Re: ADO.Net & Identity Seed fields


Dave,

If you are using SQL Server (or Oracle, but its slightly different there -
I'm assuming SQL Server since you called it an identity) you should perform
your insert in a stored procedure and return the new id using RETURN
@@IDENTITY

----- Original Message -----
From: "Dave Buckner" <Dave@N...>
To: "ADO.NET" <ado_dotnet@p...>
Sent: Monday, March 18, 2002 10:28 AM
Subject: [ado_dotnet] ADO.Net & Identity Seed fields


> Hey everyone,
>
> Does anyone have a idea of how I can return a identity field after
updating
> the data adapter when adding a new row to a table in a dataset? Here is a
> VB6 example of what I mean....
>
> with aUDT
>     rsRecordset.Fields("aField").value = .aField
>     rsRecordset.Update
>     If .IsNew Then
>       rsRecordset.Bookmark = rsRecordset.Bookmark
>       .ID = rsRecordset("ID")
>     End If
> End With
>
> Thanks,
> Dave
>
>
>
>





Message #4 by Imar Spaanjaars <Imar@S...> on Tue, 19 Mar 2002 18:20:15 +0100
Hi Dave,

Just make sure that the table your are inserting your ntext to, has an 
identity field.

Try something like this:

CREATE TABLE tblTest
         (
                 ID int NOT NULL IDENTITY (1, 1),
                 Description ntext NOT NULL
         )
GO


Then use a sproc like this:

CREATE PROCEDURE spInsertRecord

         @sLongText ntext

AS

INSERT INTO tblTest(Description) VALUES (@sLongText)

RETURN @@IDENTITY


You can use ADO.NET to retrieve the return value, or you could define an 
output parameter, and store the value of @@Identity in the output param at 
the end of the sproc.

This is a very trivial example, but it should help to get you going.

HtH

Imar



At 11:08 AM 3/19/2002 -0600, you wrote:
>Terry,
>
>Thanks for the response! I am using SQL Server. That's not a bad idea, I do
>wonder about ntext fields though. Any suggestions on these?
>
>Thanks alot!
>Dave
>
>-----Original Message-----
>From: Terry Carr [mailto:Terry.Carr@r...]
>Sent: Monday, March 18, 2002 9:43 AM
>To: ADO.NET
>Subject: [ado_dotnet] Re: ADO.Net & Identity Seed fields
>
>
>Dave,
>
>If you are using SQL Server (or Oracle, but its slightly different there -
>I'm assuming SQL Server since you called it an identity) you should perform
>your insert in a stored procedure and return the new id using RETURN
>@@IDENTITY
>
>----- Original Message -----
>From: "Dave Buckner" <Dave@N...>
>To: "ADO.NET" <ado_dotnet@p...>
>Sent: Monday, March 18, 2002 10:28 AM
>Subject: [ado_dotnet] ADO.Net & Identity Seed fields
>
>
> > Hey everyone,
> >
> > Does anyone have a idea of how I can return a identity field after
>updating
> > the data adapter when adding a new row to a table in a dataset? Here is a
> > VB6 example of what I mean....
> >
> > with aUDT
> >     rsRecordset.Fields("aField").value = .aField
> >     rsRecordset.Update
> >     If .IsNew Then
> >       rsRecordset.Bookmark = rsRecordset.Bookmark
> >       .ID = rsRecordset("ID")
> >     End If
> > End With
> >
> > Thanks,
> > Dave
> >
> >
> >
> >
>
>
>
>
>
>


Message #5 by "Dave Buckner" <Dave@N...> on Tue, 19 Mar 2002 12:16:25 -0600
Imar,

I was thinking ntext fell into the blob category that could not be
represented in that matter. Thanks for clearing this up!

Dave

-----Original Message-----
From: Imar Spaanjaars [mailto:Imar@S...]
Sent: Tuesday, March 19, 2002 11:20 AM
To: ADO.NET
Subject: [ado_dotnet] Re: ADO.Net & Identity Seed fields


Hi Dave,

Just make sure that the table your are inserting your ntext to, has an
identity field.

Try something like this:

CREATE TABLE tblTest
         (
                 ID int NOT NULL IDENTITY (1, 1),
                 Description ntext NOT NULL
         )
GO


Then use a sproc like this:

CREATE PROCEDURE spInsertRecord

         @sLongText ntext

AS

INSERT INTO tblTest(Description) VALUES (@sLongText)

RETURN @@IDENTITY


You can use ADO.NET to retrieve the return value, or you could define an
output parameter, and store the value of @@Identity in the output param at
the end of the sproc.

This is a very trivial example, but it should help to get you going.

HtH

Imar



At 11:08 AM 3/19/2002 -0600, you wrote:
>Terry,
>
>Thanks for the response! I am using SQL Server. That's not a bad idea, I do
>wonder about ntext fields though. Any suggestions on these?
>
>Thanks alot!
>Dave
>
>-----Original Message-----
>From: Terry Carr [mailto:Terry.Carr@r...]
>Sent: Monday, March 18, 2002 9:43 AM
>To: ADO.NET
>Subject: [ado_dotnet] Re: ADO.Net & Identity Seed fields
>
>
>Dave,
>
>If you are using SQL Server (or Oracle, but its slightly different there -
>I'm assuming SQL Server since you called it an identity) you should perform
>your insert in a stored procedure and return the new id using RETURN
>@@IDENTITY
>
>----- Original Message -----
>From: "Dave Buckner" <Dave@N...>
>To: "ADO.NET" <ado_dotnet@p...>
>Sent: Monday, March 18, 2002 10:28 AM
>Subject: [ado_dotnet] ADO.Net & Identity Seed fields
>
>
> > Hey everyone,
> >
> > Does anyone have a idea of how I can return a identity field after
>updating
> > the data adapter when adding a new row to a table in a dataset? Here is
a
> > VB6 example of what I mean....
> >
> > with aUDT
> >     rsRecordset.Fields("aField").value = .aField
> >     rsRecordset.Update
> >     If .IsNew Then
> >       rsRecordset.Bookmark = rsRecordset.Bookmark
> >       .ID = rsRecordset("ID")
> >     End If
> > End With
> >
> > Thanks,
> > Dave
> >
> >
> >
> >
>
>
>
>
>
>






Message #6 by Imar Spaanjaars <Imar@S...> on Tue, 19 Mar 2002 19:27:38 +0100
Even with a BLOB you could do the same. Just add an ID field to the table 
(either an Auto ID, or the ID of a record in a different table) and 
everything should work.

Imar

At 12:16 PM 3/19/2002 -0600, you wrote:
>Imar,
>
>I was thinking ntext fell into the blob category that could not be
>represented in that matter. Thanks for clearing this up!
>
>Dave
>
>-----Original Message-----
>From: Imar Spaanjaars [mailto:Imar@S...]
>Sent: Tuesday, March 19, 2002 11:20 AM
>To: ADO.NET
>Subject: [ado_dotnet] Re: ADO.Net & Identity Seed fields
>
>
>Hi Dave,
>
>Just make sure that the table your are inserting your ntext to, has an
>identity field.
>
>Try something like this:
>
>CREATE TABLE tblTest
>          (
>                  ID int NOT NULL IDENTITY (1, 1),
>                  Description ntext NOT NULL
>          )
>GO
>
>
>Then use a sproc like this:
>
>CREATE PROCEDURE spInsertRecord
>
>          @sLongText ntext
>
>AS
>
>INSERT INTO tblTest(Description) VALUES (@sLongText)
>
>RETURN @@IDENTITY
>
>
>You can use ADO.NET to retrieve the return value, or you could define an
>output parameter, and store the value of @@Identity in the output param at
>the end of the sproc.
>
>This is a very trivial example, but it should help to get you going.
>
>HtH


Message #7 by "Dave Buckner" <Dave@N...> on Tue, 19 Mar 2002 15:01:29 -0600
Imar,

I want to say thanks for this new bit of info! I must have figured somewhere
they can't be used due to their use in views?

Thanks again!
Dave

-----Original Message-----
From: Imar Spaanjaars [mailto:Imar@S...]
Sent: Tuesday, March 19, 2002 12:28 PM
To: ADO.NET
Subject: [ado_dotnet] Re: ADO.Net & Identity Seed fields


Even with a BLOB you could do the same. Just add an ID field to the table
(either an Auto ID, or the ID of a record in a different table) and
everything should work.

Imar

At 12:16 PM 3/19/2002 -0600, you wrote:
>Imar,
>
>I was thinking ntext fell into the blob category that could not be
>represented in that matter. Thanks for clearing this up!
>
>Dave
>
>-----Original Message-----
>From: Imar Spaanjaars [mailto:Imar@S...]
>Sent: Tuesday, March 19, 2002 11:20 AM
>To: ADO.NET
>Subject: [ado_dotnet] Re: ADO.Net & Identity Seed fields
>
>
>Hi Dave,
>
>Just make sure that the table your are inserting your ntext to, has an
>identity field.
>
>Try something like this:
>
>CREATE TABLE tblTest
>          (
>                  ID int NOT NULL IDENTITY (1, 1),
>                  Description ntext NOT NULL
>          )
>GO
>
>
>Then use a sproc like this:
>
>CREATE PROCEDURE spInsertRecord
>
>          @sLongText ntext
>
>AS
>
>INSERT INTO tblTest(Description) VALUES (@sLongText)
>
>RETURN @@IDENTITY
>
>
>You can use ADO.NET to retrieve the return value, or you could define an
>output parameter, and store the value of @@Identity in the output param at
>the end of the sproc.
>
>This is a very trivial example, but it should help to get you going.
>
>HtH







  Return to Index