473,785 Members | 2,309 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Best practice - handling null in sp

Sql server 7

There will be times when the user will not be required to supply a value for
the calling asp script that pass values to an sql server Sp.

How can I handle these null or empty values so I do not generate an error
for the code below....

1. Should I rewrite the sql server SP to handle the null values...

2. or should I replace the null and empty values with a dummy value.

----------------------------------------
Here is an example of my calling code:
---------------------------------------

set oConn = GetConnection()
Set oCmd = GetStoredProced ure(oConn,"sp_a dduser1")
oCmd.Parameters .append oCmd.CreatePara meter("u_id", adVarChar,
adParamInput,50 ,sID)
oCmd.Parameters .append oCmd.CreatePara meter("u_name", adVarChar,
adParamInput,50 ,sEmailName)
oCmd.Parameters .append oCmd.CreatePara meter("u_Nation ID", adVarChar,
adParamInput,12 ,sNationID)

set oReturn = oCmd.CreatePara meter("u_id", adInteger, adParamOutput)
oCmd.Parameters .append oReturn

oCmd.execute()

if oReturn.value=-1 then
'//Code
Else
'//Code
end if

------------------
STORED PROC
------------------

CREATE Procedure sp_adduser1
@u_name varchar(50),
@u_NationID int,
@u_id int output
As
set nocount on
if not exists(select u_id from t_user where u_name=@u_name)
begin
INSERT INTO t_user(u_name, u_NationID)
VALUES (@u_name@u_Nati onID)
select @u_id=@@identit y
end
else
select @u_id=-1
return
GO
Jul 19 '05 #1
1 1353
<ja***@catamara nco.com> wrote in news:OxRihcYoEH A.2900
@TK2MSFTNGP12.p hx.gbl:
How can I handle these null or empty values so I do not generate an error
for the code below....


Top of my head, the easiest way would be to use IsNull in the sproc...

INSERT INTO t_user(u_name, u_NationID)
VALUES (IsNull(@u_name ,''),IsNull(@u_ NationID,''))
Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
1831
by: Johannes Hansen | last post by:
What are the best practice on handling an exception caused by a Dispose method when its called from inside a loop? Wrap the entire loop in a try-catch or do the try-catch on each iteration to get as many of the object Disposed as possible? Take the following example: Bitmap bmpArray = ... // Some fancy bitmap array. try {
136
9458
by: Matt Kruse | last post by:
http://www.JavascriptToolbox.com/bestpractices/ I started writing this up as a guide for some people who were looking for general tips on how to do things the 'right way' with Javascript. Their code was littered with document.all and eval, for example, and I wanted to create a practical list of best practices that they could easily put to use. The above URL is version 1.0 (draft) that resulted. IMO, it is not a replacement for the FAQ,...
4
2002
by: Sandy | last post by:
Hello - I read an interesting article on the web wherein the author states he doesn't handle too many errors at page level, but handles them at the application level. He further goes on to show how error logging can be incorporated using a Sql Server log with an additional text log in case Sql Server was down. My inclination after reading the article is to use Try-Catch-Finally as little as possible (tends to slow things if you have...
4
7618
by: James Radke | last post by:
Hello, I am looking for guidance on best practices to incorporate effective and complete error handling in an application written in VB.NET. If I have the following function in a class module (note that this class module represents the business layer of code NOT the gui layer): Public Function Test(ByVal Parm1 As Integer, ByVal Parm2 As Integer) As SqlDataReader ' Declare the SQL data layer class Dim oSQL As New...
6
2103
by: RonL | last post by:
What is the recommended best technique for handling errors/exceptions in ASP.Net. I've read about the following techniques: 1. Try/Catch 2. Page_Error 3. Application_Error in the glabal.asax 4. Custom errors in Web.Config.
5
1736
by: csgraham74 | last post by:
Hi guys, Basically i have been developing in dotnet for a couple of years but ive had a few issues in regards to error handling. For example - I have a class that i call passing in a stored procedure and connection string as a path. My method returns a dataset. In my SP i have an output parameter which tells me whether the SP select is successful or not. If i get a error code passed back then i throw an exception this then returns...
1
8084
by: TEK | last post by:
Hello I'm having some questions regarding the implementation of IPropertyChanged interface. Status: I have the basic stuff up and running, and on every property change I get a call to my OnPropertyChanged method with the correct property name.
5
2467
by: =?Utf-8?B?QmlsbHk=?= | last post by:
asp.net 2.0 vs2005 What is best practice for exception handling on a website in vs2005? I was going to catch errors in application on_error event, log them to the event log, then send users to an error page. But looking at the event log, asp.net 2.0 logs those errors anyways, with more detail than i cen get from the exception object. So is there any point logging them to the event log, is it jsut better to let .net do this and get the...
2
2359
by: stephen.diverdi | last post by:
I have a question about what's the best way to handle something in C++ without a lot of redundant code and void*s because I don't seem to be able to avoid them both. I've run into it before and always sort of hacked something together, but I'd really prefer a more elegant solution. I have a parameter struct that I store some values of varying type in: struct params_t {
0
9647
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
9489
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10357
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
9959
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
7509
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
6744
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
5396
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
5528
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4063
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 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.