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

  • Thread starter Thread starter ASP .NET Newbie
  • Start date Start date
A

ASP .NET Newbie

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?!
 
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
 
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
 
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
 
Back
Top