473,396 Members | 1,785 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,396 software developers and data experts.

Get a return value from a StoredProcedure

144 100+
hi,

is there anyway to know whether a INSERT/UPDATE/DELETE stored procedured was executed successfully?

for example, if i have the following StoredProcedure:

Expand|Select|Wrap|Line Numbers
  1. create procedure sp_add_employee
  2. @userid int,
  3. @password varchar(20)
  4. as
  5. insert into employee values(@userid,@password)
  6.  
can i get a return value from the stored procedure to know whether the insert is success/failure?

Thank you.
Oct 23 '08 #1
1 2091
deepuv04
227 Expert 100+
hi,

use exception handling (try catch blocks) and return some value which will convey the result of the sp.

for example
create procedure sp_add_employee
@userid int,
@password varchar(20)
@Result INT OUTPUT
as
BEGIN
BEGIN TRY
insert into employee values(@userid,@password)
SET @Result = 1
END TRY
BEGIN CATCH
SET @Result = 0
END CATCH

SELECT @Result
END

on executing this if you get the result as 1 means success if 0 failure.


thanks.
Oct 23 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Scott Natwick | last post by:
Hi, Is there a way to obtain the return code from a stored procedure? Here is what I have so far. The procedure executes, but I'm not able to find the return code from the procedure. ...
8
by: Nick | last post by:
Hi, I'm trying to add some data on a company to an SQL server (which I can do), and want to return the FirmID (SQL identity) of the data that was just inserted so I can use it to redirect to...
3
by: tshad | last post by:
I am trying to set up a class to handle my database accesses. I can't seem to figure out how to get the return value from my dataReader from these routines (most of which I got elsewhere). They...
2
by: Hardik Shah | last post by:
Hi, I have created a sql stored procedure which returns two values. it runs successfully from query analyser. I want to run it from my vb.net code , it runs without any error but it don't store...
7
by: Rudy | last post by:
Hello All! I have a value in a textbox(txbTableIDm.Text ) that I would like to use in a paremiter in a SP I wrote, and then have the select statement work off that parememter, retireive a...
2
by: Hrvoje Voda | last post by:
I'm using this store procedure to return data from sql server. SqlDataReader sqlRead = null; System.Data.SqlClient.SqlCommand ProfileBLOBSelect = new System.Data.SqlClient.SqlCommand(); ...
8
by: Andrew Robinson | last post by:
Are these two equivalent? Is one better than the other? I tend to go with #1 but started wondering.... Thanks, 1: using (SqlConnection cn = new SqlConnection(DataConnection)) using...
4
by: Brian Parker | last post by:
I've been banging my head on this for hours and it's something that should be very very easy. I have a Stored Procedure in a MS-SQL 2000 server that returns a Varchar(40) and I want to grab that...
4
by: =?Utf-8?B?QmFidU1hbg==?= | last post by:
Hi, I have a GridView and a SqlDataSource controls on a page. The SqlDataSource object uses stored procedures to do the CRUD operations. The DataSource has three columns one of which -...
3
by: BombDrop | last post by:
Can any one help I have a method that will return a List to be bound as a datasource to a combobox see code for population below. I get the following error when i try to compile Error 29 ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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,...

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.