472,342 Members | 1,930 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,342 software developers and data experts.

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 1611
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Alex | last post by:
I have a "source" table that is being populated by a DTS bulk import of a text file. I need to scrub the source table after the import step by...
2
by: xAvailx | last post by:
I have a requirement that requires detection of rows deleted/updated by other processes. My business objects call stored procedures to create,...
7
by: Egyd Csaba | last post by:
Hi, I've a problem with some of my stored procs. My config is: RH7.1, Postgres 7.3.2 I had converted a few fields of a few tables from one type...
18
by: Bill Smith | last post by:
The initial row is inserted with the colPartNum column containing a valid LIKE pattern, such as (without the single quotes) 'AB%DE'. I want to...
1
by: mike | last post by:
If I try and do a "SELECT IDENTITY_VAL_LOCAL() FROM SYSIBM.SYSDUMMY1" after I have run a stored procedure in DB2 version 7.2, I get the last...
4
by: mattgcon | last post by:
When I use a stored procedure to insert data into a table and when the Datagrid refreshes two new columns are added. The dataSet is set up with one...
4
by: Learner | last post by:
Hi there, I have a storec proc that schedules a Sql job and finally it returns 0 then it was successfull and if it returns 1 then its unsuccessful....
15
by: Jay | last post by:
I have a multi threaded VB.NET application (4 threads) that I use to send text messages to many, many employees via system.timer at a 5 second...
3
by: andrewkl | last post by:
hi, I have the following Perl code that inserts a string to an Oracle DB via a stored procedure: #!/usr/local/bin/perl ## Perl v5.8.6...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.