473,378 Members | 1,447 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 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 1697
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 running appropriate stored proc(s) to copy the source...
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, read, update, delete data in a SQL Server 2000 data...
7
by: Együd 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 to another and after this I made all the...
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 update the column value with the results of a query...
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 generated Key before the CallableStatement was executed...
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 table with NO columns defined. Please help me on...
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. Now when i run the stored proc in the query...
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 interval. Basically, I look in a SQL table (queue) to...
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 built for sun4-solaris use strict; BEGIN...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.