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: -
create procedure sp_add_employee
-
@userid int,
-
@password varchar(20)
-
as
-
insert into employee values(@userid,@password)
-
How do I know whether the insert is successful?
Please advise.
Thanks
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 -
UPDATE employee
-
SET Password=@password
-
WHERE
-
UserID= @userid
-
You could modify it do say this: -
SELECT @AffectedRows=count(*)
-
FROM employee
-
WHERE
-
UserID= @userid
-
-
UPDATE employee
-
SET Password=@password
-
WHERE
-
UserID= @userid
-
-
return @AffectedRows
-
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
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
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
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.
hi,
thanks for the reply.
just now i was practicing using output parameter from StoredProcedure .
i have the following StoredProcedure -
create procedure sp_get_supplier_code
-
(
-
@supplier_code char(3) output
-
)
-
as
-
set nocount on
-
set @supplier_code = 'SP'
-
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 -
MsgBox(sqlCmd.Parameters("@supplied_code").Value)
-
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
Plater 7,872
Recognized Expert Expert
try varchar instead of char ?
hello,
thanks for the reply. i've changed it to varchar, but still i only get an 'S'.
Thank you
Plater 7,872
Recognized Expert Expert
How did you define the @supplied_code in code side, as what data type?
i define it as SqlDbType.VarCh ar
here's the code that define it -
MainForm.dbCon.addOutputParameter("@supplier_code_output", "", SqlDbType.VarChar)
-
(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 -
Public Sub addOutputParameter(ByVal key As String, ByVal value As String, _
-
ByVal type As SqlDbType)
-
Dim sqlParam As New SqlParameter()
-
-
sqlParam.ParameterName = key
-
sqlParam.Value = value
-
sqlParam.SqlDbType = type
-
sqlParam.Direction = ParameterDirection.Output
-
-
sqlParams.Add(sqlParam)
-
-
'register it to sqlOutput, so it's available to outside class
-
sqlOutput.Add(key, value)
-
End Sub
-
Thank you.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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.
|
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 =
|
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?
|
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...
|
by: kathy |
last post by:
what is the better way to determine if a string is number or not?
| |
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,
|
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
|
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() )
{
....
|
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
|
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...
|
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...
| |
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...
|
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...
|
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();...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |