473,664 Members | 2,728 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

StoredProcedure e - determine success/failure

144 New Member
Hi,

how do i determine whether a INSERT/UPDATE/DELETE stored procedure is successed/failured.


if for example, I have the following stored proc here:

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.  
How do I know whether the insert is successful?


Please advise.

Thanks
Oct 23 '08 #1
9 1142
Plater
7,872 Recognized Expert Expert
For that Insert statement, if it failed, an Exception would have been thrown.

Updates and Deletes are trickier
If you had for example
Expand|Select|Wrap|Line Numbers
  1. UPDATE employee 
  2. SET Password=@password
  3. WHERE
  4. UserID= @userid
  5.  
You could modify it do say this:
Expand|Select|Wrap|Line Numbers
  1. SELECT @AffectedRows=count(*)
  2. FROM employee
  3. WHERE
  4. UserID= @userid
  5.  
  6. UPDATE employee 
  7. SET Password=@password
  8. WHERE
  9. UserID= @userid
  10.  
  11. return @AffectedRows
  12.  
That should tell you how many rows were effected by the UPDATE command (0 rows, 1 row, 36 rows, whatever the case may be)
You can do similar for the DELETE command
Oct 23 '08 #2
nateraaaa
663 Recognized Expert Contributor
You need to add error handling to your stored procedure. Check out this link for more information. Pay particular attention to the @@ERROR system function.

Nathan
Oct 23 '08 #3
azizonin
2 New Member
Dear Friend,

I will suggest you to write the query in sql server itself and run at the same time, it will let you know the error if you passing through, and i think just copy the codes written in the fronthand and just paste to the sql server and just, follow the errors and you would like to learn the more as you indulje to write more queries there..

Regds
Aziz
Oct 24 '08 #4
ssmeshack
38 New Member
Dear Friend,

I will suggest you to write the query in sql server itself and run at the same time, it will let you know the error if you passing through, and i think just copy the codes written in the fronthand and just paste to the sql server and just, follow the errors and you would like to learn the more as you indulje to write more queries there..

Regds
Aziz
I always do like what Aziz suggest.
Oct 24 '08 #5
thesti
144 New Member
hi,

thanks for the reply.

just now i was practicing using output parameter from StoredProcedure .
i have the following StoredProcedure

Expand|Select|Wrap|Line Numbers
  1. create procedure sp_get_supplier_code
  2. (
  3.     @supplier_code char(3) output
  4. )
  5. as
  6.     set nocount on
  7.     set @supplier_code = 'SP'
  8.  
then i try to access it by creating a SqlConnection and a SqlCommand and setup the output parameter, then i execute it using sqlCmd.executeN onQuery(), then i try to access the output parameter by using the following code

Expand|Select|Wrap|Line Numbers
  1. MsgBox(sqlCmd.Parameters("@supplied_code").Value)
  2.  
but i only get an "S" from the messagebox, it seems that it only return the first character of 'SP'. is there something wrong?

Thank you
Oct 25 '08 #6
Plater
7,872 Recognized Expert Expert
try varchar instead of char ?
Oct 27 '08 #7
thesti
144 New Member
hello,

thanks for the reply. i've changed it to varchar, but still i only get an 'S'.

Thank you
Oct 29 '08 #8
Plater
7,872 Recognized Expert Expert
How did you define the @supplied_code in code side, as what data type?
Oct 29 '08 #9
thesti
144 New Member
i define it as SqlDbType.VarCh ar

here's the code that define it
Expand|Select|Wrap|Line Numbers
  1. MainForm.dbCon.addOutputParameter("@supplier_code_output", "", SqlDbType.VarChar)
  2.  
(in the example above i've changed the parameter name to @supplier_code_ output).
in the program i have a class which encapsulate a DBConnection to the SQL Server 2K.

here's the definition of the addOutputParame ter method

Expand|Select|Wrap|Line Numbers
  1. Public Sub addOutputParameter(ByVal key As String, ByVal value As String, _
  2.                                 ByVal type As SqlDbType)
  3.         Dim sqlParam As New SqlParameter()
  4.  
  5.         sqlParam.ParameterName = key
  6.         sqlParam.Value = value
  7.         sqlParam.SqlDbType = type
  8.         sqlParam.Direction = ParameterDirection.Output
  9.  
  10.         sqlParams.Add(sqlParam)
  11.  
  12.         'register it to sqlOutput, so it's available to outside class
  13.         sqlOutput.Add(key, value)
  14.     End Sub
  15.  
Thank you.
Oct 29 '08 #10

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

Similar topics

1
2267
by: audipen | last post by:
Hi, I trap the 'OnBuildProjConfigDone' and perform some custom enhancement to the assembly. I check the 'bool Success' parameter before I perform my step. I go ahead only if 'Success == true" My question is - Is there any way in which I can indicate success or failure of my post build step.. 'Success' is an in-parameter, so I cant set it to false. Also the return type of the handler is void.
7
4408
by: MLH | last post by:
I have been using variations of the following to determine whether a functional connection to internet exists. I'm thinking of replacing it with a simple PING, but I've never seen any code for that. What is your opinion on the alternative strategy? Have you ever tried it? On Error GoTo Err_Handler Dim msXML As Object, strPageContent As String, MyURL As String 10 Set msXML = CreateObject("Microsoft.XMLHTTP") 20 MyURL =
0
1145
by: spam.noam | last post by:
Hello, What is the convention for writing C functions which don't return a value, but can fail? If I understand correctly, 1. PyArg_ParseTuple returns 0 on failure and 1 on success. 2. PySet_Add returns -1 on failure and 0 on success. Am I correct? What should I do with new C functions that I write?
0
1334
by: Marc DVer | last post by:
I have a stored procedure that has a simple insert statement. I want to be able to tell if the insert statement executed successfully, and return using a tinyint whether the statement was successful or not. My googling efforts did not result in anything useful, probably because I do not know the proper terminology. I am using mysql-5.0.18-nt. So, the question is, what syntax is used to trap a result code from an insert query, and what...
2
1674
by: kathy | last post by:
what is the better way to determine if a string is number or not?
25
6532
by: lovecreatesbeauty | last post by:
Hello experts, I write a function named palindrome to determine if a character string is palindromic, and test it with some example strings. Is it suitable to add it to a company/project library as a small tool function according to its quality? I will be very happy to get your suggestion from every aspect on it: interface design, C language knowledge or algorithm efficient. Sincerely,
9
1636
by: Joris De Groote | last post by:
Hi, I'm looking for a javascript that can give me the screensize of a computer. Can anyone help me? Thanks
6
5779
by: magix | last post by:
Hi, when I read entries in file i.e text file, how can I determine the first line and the last line ? I know the first line of entry can be filtered using counter, but how about the last line of entry in EOF while loop ? while (! file.eof() ) { ....
1
1632
by: Christopher Corbell | last post by:
This question pertains to PyUnit, esp. unittest.TestCase subclasses. Does anyone know of a way from within the TestCase tearDown() method to determine whether the current test succeeded or not? What I'm after is a specialized clean-up approach for error/failure cases. This is somewhat related to some earlier threads in this group about using fixtures across test invocations. I'm functionally testing a
0
8437
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8861
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8636
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6187
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5660
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4185
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4351
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2764
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
2
2003
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.