470,631 Members | 1,635 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,631 developers. It's quick & easy.

HELP - Stored Proc/Insert Stmt/Return column value...

I am trying to insert a new record into my database, and have it return a
uniqueidentifier as the "newcatid". I don't use integers as my "id"'s, but
rather uniqueidentifiers. Here's my Stored Proc:

ALTER PROCEDURE dbo.spNewCat
(
@newcatidID uniqueidentifier OUTPUT,
@catname varchar(50) )
AS
INSERT INTO Categories (catname) VALUES (@catname)
/* SET NOCOUNT ON */
RETURN

Any help please?!

Nov 20 '05 #1
3 1546
Since the GUID doesn't have to come from the db, I would create it on the
client and pass it to your sproc...

Here is just a bunch of random code that uses GUID's client side, hope it is
not too confusing. :^)

Dim g As Guid
g = System.Guid.NewGuid

cmd.Parameters.Add(New SqlParameter("@GUID", SqlDbType.UniqueIdentifier,
16)).Value = g

Dim myGUID(8) As Byte
myGUID = g.ToByteArray

myGUID = CType(dr.GetSqlBinary(0).Value, Byte())

myGUID = CType(cmd.Parameters("@GUID").Value, Byte())

HTH,
Greg

"ASP .NET Newbie" <Ch*********@ProspectiveLink.com> wrote in message
news:u5**************@TK2MSFTNGP12.phx.gbl...
I am trying to insert a new record into my database, and have it return a
uniqueidentifier as the "newcatid". I don't use integers as my "id"'s, but rather uniqueidentifiers. Here's my Stored Proc:

ALTER PROCEDURE dbo.spNewCat
(
@newcatidID uniqueidentifier OUTPUT,
@catname varchar(50) )
AS
INSERT INTO Categories (catname) VALUES (@catname)
/* SET NOCOUNT ON */
RETURN

Any help please?!

Nov 20 '05 #2
Should also mention, if you still want to do it on the server then:

ALTER PROCEDURE dbo.spNewCat
(
@newcatidID uniqueidentifier OUTPUT,
@catname varchar(50) )
AS

SET @newcatidID = NEWID()

INSERT INTO Categories (catidID, catname) VALUES (@newcatidID,@catname)

Greg
"Greg Burns" <greg_burns@DONT_SPAM_ME_hotmail.com> wrote in message
news:%2******************@tk2msftngp13.phx.gbl...
Since the GUID doesn't have to come from the db, I would create it on the
client and pass it to your sproc...

Here is just a bunch of random code that uses GUID's client side, hope it
is
not too confusing. :^)

Dim g As Guid
g = System.Guid.NewGuid

cmd.Parameters.Add(New SqlParameter("@GUID", SqlDbType.UniqueIdentifier,
16)).Value = g

Dim myGUID(8) As Byte
myGUID = g.ToByteArray

myGUID = CType(dr.GetSqlBinary(0).Value, Byte())

myGUID = CType(cmd.Parameters("@GUID").Value, Byte())

HTH,
Greg

"ASP .NET Newbie" <Ch*********@ProspectiveLink.com> wrote in message
news:u5**************@TK2MSFTNGP12.phx.gbl...
I am trying to insert a new record into my database, and have it return a
uniqueidentifier as the "newcatid". I don't use integers as my "id"'s,

but
rather uniqueidentifiers. Here's my Stored Proc:

ALTER PROCEDURE dbo.spNewCat
(
@newcatidID uniqueidentifier OUTPUT,
@catname varchar(50) )
AS
INSERT INTO Categories (catname) VALUES (@catname)
/* SET NOCOUNT ON */
RETURN

Any help please?!


Nov 20 '05 #3
This is actually the approach I went with. I had done it on the client side
in ASP, but I'm in ASP.NET development now, and changing things over to
utilize Stored Procedures.

Thanks for your help!

Chad

"Greg Burns" <greg_burns@DONT_SPAM_ME_hotmail.com> wrote in message
news:O1**************@TK2MSFTNGP09.phx.gbl...
Should also mention, if you still want to do it on the server then:

ALTER PROCEDURE dbo.spNewCat
(
@newcatidID uniqueidentifier OUTPUT,
@catname varchar(50) )
AS

SET @newcatidID = NEWID()

INSERT INTO Categories (catidID, catname) VALUES (@newcatidID,@catname)

Greg
"Greg Burns" <greg_burns@DONT_SPAM_ME_hotmail.com> wrote in message
news:%2******************@tk2msftngp13.phx.gbl...
Since the GUID doesn't have to come from the db, I would create it on the client and pass it to your sproc...

Here is just a bunch of random code that uses GUID's client side, hope it is
not too confusing. :^)

Dim g As Guid
g = System.Guid.NewGuid

cmd.Parameters.Add(New SqlParameter("@GUID", SqlDbType.UniqueIdentifier,
16)).Value = g

Dim myGUID(8) As Byte
myGUID = g.ToByteArray

myGUID = CType(dr.GetSqlBinary(0).Value, Byte())

myGUID = CType(cmd.Parameters("@GUID").Value, Byte())

HTH,
Greg

"ASP .NET Newbie" <Ch*********@ProspectiveLink.com> wrote in message
news:u5**************@TK2MSFTNGP12.phx.gbl...
I am trying to insert a new record into my database, and have it return a uniqueidentifier as the "newcatid". I don't use integers as my "id"'s,

but
rather uniqueidentifiers. Here's my Stored Proc:

ALTER PROCEDURE dbo.spNewCat
(
@newcatidID uniqueidentifier OUTPUT,
@catname varchar(50) )
AS
INSERT INTO Categories (catname) VALUES (@catname)
/* SET NOCOUNT ON */
RETURN

Any help please?!



Nov 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

18 posts views Thread by Bill Smith | last post: by
4 posts views Thread by mattgcon | last post: by
15 posts views Thread by Jay | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.