473,549 Members | 2,745 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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

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

Any help please?!

Nov 20 '05 #1
3 1711
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.New Guid

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

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

myGUID = CType(dr.GetSql Binary(0).Value , Byte())

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

HTH,
Greg

"ASP .NET Newbie" <Ch*********@Pr ospectiveLink.c om> wrote in message
news:u5******** ******@TK2MSFTN GP12.phx.gbl...
I am trying to insert a new record into my database, and have it return a
uniqueidentifie r as the "newcatid". I don't use integers as my "id"'s, but rather uniqueidentifie rs. Here's my Stored Proc:

ALTER PROCEDURE dbo.spNewCat
(
@newcatidID uniqueidentifie r 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 uniqueidentifie r OUTPUT,
@catname varchar(50) )
AS

SET @newcatidID = NEWID()

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

Greg
"Greg Burns" <greg_burns@DON T_SPAM_ME_hotma il.com> wrote in message
news:%2******** **********@tk2m sftngp13.phx.gb l...
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.New Guid

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

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

myGUID = CType(dr.GetSql Binary(0).Value , Byte())

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

HTH,
Greg

"ASP .NET Newbie" <Ch*********@Pr ospectiveLink.c om> wrote in message
news:u5******** ******@TK2MSFTN GP12.phx.gbl...
I am trying to insert a new record into my database, and have it return a
uniqueidentifie r as the "newcatid". I don't use integers as my "id"'s,

but
rather uniqueidentifie rs. Here's my Stored Proc:

ALTER PROCEDURE dbo.spNewCat
(
@newcatidID uniqueidentifie r 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@DON T_SPAM_ME_hotma il.com> wrote in message
news:O1******** ******@TK2MSFTN GP09.phx.gbl...
Should also mention, if you still want to do it on the server then:

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

SET @newcatidID = NEWID()

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

Greg
"Greg Burns" <greg_burns@DON T_SPAM_ME_hotma il.com> wrote in message
news:%2******** **********@tk2m sftngp13.phx.gb l...
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.New Guid

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

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

myGUID = CType(dr.GetSql Binary(0).Value , Byte())

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

HTH,
Greg

"ASP .NET Newbie" <Ch*********@Pr ospectiveLink.c om> wrote in message
news:u5******** ******@TK2MSFTN GP12.phx.gbl...
I am trying to insert a new record into my database, and have it return a uniqueidentifie r as the "newcatid". I don't use integers as my "id"'s,

but
rather uniqueidentifie rs. Here's my Stored Proc:

ALTER PROCEDURE dbo.spNewCat
(
@newcatidID uniqueidentifie r 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
3253
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 data to 2 normalized tables. The problem is that table "Companies" needs to be populated first in order to generate the Identity ID and then use...
2
5109
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 store. I've done a fair amount of research on concurrency handling in newsgroups and other resources. Below is what I've come up as a standard for...
7
3509
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 necessary changes on the functions and recreated all my types and functions. It seemd to be all right, but the newly created functions won't work anymore.
18
5945
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 against a different table (that uses the LIKE predicate) but cannot get around the SQL0132 error . I have tried the hex notation after the LIKE such...
1
2790
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 in the transaction and not the key generated in my stored procedure. Is there a way to set the IDENTITY_VAL_LOCAL or have the stored procedure...
4
1327
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 this. I have screen shots of the before and after. Here is the code: sqlCommand.CommandType = CommandType.StoredProcedure;...
4
3042
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 analyzer its returning SQLServerAgent is not currently running so it cannot be notified of this action. Stored Procedure:...
15
2560
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 determine who needs to receive the text message then send the message to the address. Only problem is, the employee may receive up to 4 of the...
3
4161
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 { $ENV{'TNS_ADMIN'} = '/auto/engweb/oracle/sqlnet'; $ENV{'ORACLE_HOME'} = '/usr/packages/dbdoracle/9.2.0'; }
0
7450
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7957
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6043
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5368
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5088
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3500
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3481
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1941
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
763
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.