?
Solved

return id after adding record store procedure

Posted on 2005-04-04
4
Medium Priority
?
217 Views
Last Modified: 2010-04-07
Hi,

How can we query the autonumber after inserting?

id called stsn

Thanks.


create proc [dbo].[SP_shift_break_add]
@break1 datetime,
@break2 datetime,
@lunch datetime
as
insert into shiftbreak_master (lunch,break1,break2) values (@lunch,@break1,@break2)
select @@identity as 'stsn'


GO
0
Comment
Question by:lynnton
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 23

Expert Comment

by:b1xml2
ID: 13699466
'cmd is the SqlCommand object
Dim id As Int = CInt(cmd.ExecuteScalar())
0
 
LVL 23

Expert Comment

by:b1xml2
ID: 13699469
typo
===
 'cmd is the SqlCommand object
Dim id As Integer = CInt(cmd.ExecuteScalar())
0
 
LVL 1

Author Comment

by:lynnton
ID: 13699563
b1xml2,

What could be happening when I try to add; it always returns 0. How can we troubleshoot?

Thanks.


                                    cmd.CommandType = CommandType.StoredProcedure
                                    cmd.CommandText = "SP_shift_break_add"
                                    cmd.Parameters.Add(New SqlParameter("@RETURN_VALUE", SqlDbType.Int, 4, ParameterDirection.ReturnValue, False, CType(0, Byte), CType(0, Byte), "", DataRowVersion.Current, Nothing))
                                    cmd.Parameters.Add("@lunch",SqlDbType.datetime).Value = DirectCast(Me.FindControl(String.Format("txtlb{0}",count)),textbox).text
                                    cmd.Parameters.Add("@break1",SqlDbType.datetime).Value =  DirectCast(Me.FindControl(String.Format("txtfb{0}",count)),textbox).text
                                    cmd.Parameters.Add("@break2",SqlDbType.datetime).Value =  DirectCast(Me.FindControl(String.Format("txtsb{0}",count)),textbox).text
                                    cmd.executenonquery()
                                    returnvalue = cmd.parameters("@RETURN_VALUE").value
                                    cmd.dispose
                                    cmd.parameters.clear

                                label1.text=returnvalue

0
 
LVL 23

Accepted Solution

by:
b1xml2 earned 2000 total points
ID: 13699718
the return_value is not being used in your stored proc...

change it like so and then you shd be able to use the return param...

create proc [dbo].[SP_shift_break_add]
@break1 datetime,
@break2 datetime,
@lunch datetime
as
insert into shiftbreak_master (lunch,break1,break2) values (@lunch,@break1,@break2)
RETURN @@identity
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses
Course of the Month12 days, 10 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question