By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,928 Members | 1,210 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,928 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a
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.