I have the following code that calles a stored proc in SQLServer. When the
output parameter @custref is null (System.DBNull) I cant seem to find a
test for this and I get an exception. I know I could coalesce the stored
proc, but I would like to know if the value is null.
How do you test for null in the returned parameter of a stored proc?
TIA
Andrew.
Dim retstr As String = ""
' Create Instance of Connection and Command Object
Dim myConnection As SqlConnection = New SqlConnection(Me.sSqlString)
Dim myCommand As SqlCommand = New SqlCommand("bo_getCustRef", myConnection)
' Mark the Command as a SPROC
myCommand.CommandType = CommandType.StoredProcedure
' Add Parameters to SPROC
Dim parameterCode As SqlParameter = New SqlParameter("@CustCode",
SqlDbType.NVarChar, 8)
parameterCode.Value = code
myCommand.Parameters.Add(parameterCode)
Dim parameterRef As SqlParameter = New SqlParameter("@custRef",
SqlDbType.NVarChar, 20)
parameterRef.Direction = ParameterDirection.Output
myCommand.Parameters.Add(parameterRef)
Try
myConnection.Open()
myCommand.ExecuteNonQuery()
Catch XcpInvOp As System.Exception
Finally
myConnection.Close()
myConnection.Dispose()
myConnection = Nothing
If Not parameterRef.Value Is Nothing Then
retstr = CStr(parameterRef.Value)
End If
End Try
Return retstr 4 5981
"Andrew Baker" <no@spam.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl... I have the following code that calles a stored proc in SQLServer. When
the output parameter @custref is null (System.DBNull) I cant seem to find a test for this and I get an exception. I know I could coalesce the stored proc, but I would like to know if the value is null.
How do you test for null in the returned parameter of a stored proc?
TIA Andrew. Dim retstr As String = ""
' Create Instance of Connection and Command Object
Dim myConnection As SqlConnection = New SqlConnection(Me.sSqlString)
Dim myCommand As SqlCommand = New SqlCommand("bo_getCustRef",
myConnection) ' Mark the Command as a SPROC
myCommand.CommandType = CommandType.StoredProcedure
' Add Parameters to SPROC
Dim parameterCode As SqlParameter = New SqlParameter("@CustCode", SqlDbType.NVarChar, 8)
parameterCode.Value = code
myCommand.Parameters.Add(parameterCode)
Dim parameterRef As SqlParameter = New SqlParameter("@custRef", SqlDbType.NVarChar, 20)
parameterRef.Direction = ParameterDirection.Output
myCommand.Parameters.Add(parameterRef)
Try
myConnection.Open()
myCommand.ExecuteNonQuery()
Catch XcpInvOp As System.Exception
Finally
myConnection.Close()
myConnection.Dispose()
myConnection = Nothing
If Not parameterRef.Value Is Nothing Then
Can't you check the Value for System.DBNull here..that is something like..
If Not parameterRef.Value = System.DBNull Then
???
retstr = CStr(parameterRef.Value)
End If
End Try
Return retstr
"I know I could coalesce the stored proc, but I would like to know if the
value is null."
I used to use COALESCE until I learned about ISNULL. It is more efficient.
To check for null in a parameter use:
If Not parameterRef.Value Is System.DBNull.Value Then
HTH,
Greg
"Imran Koradia" <no****@microsoft.com> wrote in message
news:uN*************@TK2MSFTNGP12.phx.gbl... "Andrew Baker" <no@spam.com> wrote in message news:%2****************@TK2MSFTNGP09.phx.gbl... I have the following code that calles a stored proc in SQLServer. When the output parameter @custref is null (System.DBNull) I cant seem to find a test for this and I get an exception. I know I could coalesce the
stored proc, but I would like to know if the value is null.
How do you test for null in the returned parameter of a stored proc?
TIA Andrew. Dim retstr As String = ""
' Create Instance of Connection and Command Object
Dim myConnection As SqlConnection = New SqlConnection(Me.sSqlString)
Dim myCommand As SqlCommand = New SqlCommand("bo_getCustRef", myConnection) ' Mark the Command as a SPROC
myCommand.CommandType = CommandType.StoredProcedure
' Add Parameters to SPROC
Dim parameterCode As SqlParameter = New SqlParameter("@CustCode", SqlDbType.NVarChar, 8)
parameterCode.Value = code
myCommand.Parameters.Add(parameterCode)
Dim parameterRef As SqlParameter = New SqlParameter("@custRef", SqlDbType.NVarChar, 20)
parameterRef.Direction = ParameterDirection.Output
myCommand.Parameters.Add(parameterRef)
Try
myConnection.Open()
myCommand.ExecuteNonQuery()
Catch XcpInvOp As System.Exception
Finally
myConnection.Close()
myConnection.Dispose()
myConnection = Nothing
If Not parameterRef.Value Is Nothing Then
Can't you check the Value for System.DBNull here..that is something like.. If Not parameterRef.Value = System.DBNull Then ???
retstr = CStr(parameterRef.Value)
End If
End Try
Return retstr
Greg your a champion.
I had tried If Not parameterRef.Value = System.DBNull.Value Then
which was a compile error.
One click and 3 characters later and it works :)
Andrew
"Greg Burns" <greg_burns@DONT_SPAM_ME_hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl... "I know I could coalesce the stored proc, but I would like to know if the value is null."
I used to use COALESCE until I learned about ISNULL. It is more efficient.
To check for null in a parameter use:
If Not parameterRef.Value Is System.DBNull.Value Then
HTH, Greg "Imran Koradia" <no****@microsoft.com> wrote in message news:uN*************@TK2MSFTNGP12.phx.gbl... "Andrew Baker" <no@spam.com> wrote in message news:%2****************@TK2MSFTNGP09.phx.gbl... I have the following code that calles a stored proc in SQLServer.
When the output parameter @custref is null (System.DBNull) I cant seem to find
a test for this and I get an exception. I know I could coalesce the stored proc, but I would like to know if the value is null.
How do you test for null in the returned parameter of a stored proc?
TIA Andrew. Dim retstr As String = ""
' Create Instance of Connection and Command Object
Dim myConnection As SqlConnection = New SqlConnection(Me.sSqlString)
Dim myCommand As SqlCommand = New SqlCommand("bo_getCustRef", myConnection) ' Mark the Command as a SPROC
myCommand.CommandType = CommandType.StoredProcedure
' Add Parameters to SPROC
Dim parameterCode As SqlParameter = New SqlParameter("@CustCode", SqlDbType.NVarChar, 8)
parameterCode.Value = code
myCommand.Parameters.Add(parameterCode)
Dim parameterRef As SqlParameter = New SqlParameter("@custRef", SqlDbType.NVarChar, 20)
parameterRef.Direction = ParameterDirection.Output
myCommand.Parameters.Add(parameterRef)
Try
myConnection.Open()
myCommand.ExecuteNonQuery()
Catch XcpInvOp As System.Exception
Finally
myConnection.Close()
myConnection.Dispose()
myConnection = Nothing
If Not parameterRef.Value Is Nothing Then
Can't you check the Value for System.DBNull here..that is something
like.. If Not parameterRef.Value = System.DBNull Then ???
retstr = CStr(parameterRef.Value)
End If
End Try
Return retstr
"Andrew Baker" <no@spam.com> wrote in message
news:OW*************@TK2MSFTNGP11.phx.gbl... I had tried If Not parameterRef.Value = System.DBNull.Value Then which was a compile error.
Null never "equals" anything. All expressions involving Null return Null
(except concatenating an empty string, which returns the empty string) and
Null is treated as Boolean False. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: CJM |
last post by:
I frequently come across a small problem with my stored procedures; there
are plenty of way around it, but I'm figuring that maybe my approach is
subtly wrong.
My typical code to call an Stored...
|
by: ImraneA |
last post by:
Hi there
I had pleasure of upsizing Access v97 db to Access v2K/SQL 2K.
Wish to provide some knowledge gained back to community - hopefully
help others.
1.Question how do you test stored...
|
by: Vern |
last post by:
I'm using the Microsoft Enterprise Data Access block to call the stored
procedure. One of the values the stored procedure returns is the stop date.
When the stop date is null, the program crashes....
|
by: Learner |
last post by:
Hi there,
I have a storec proc that schedules a Sql job and finally it returns
0 then it was successfull and if it returns 1 then its unsuccessful.
Now when i run the stored proc in the query...
|
by: syntego |
last post by:
I think I have discovered a bug in the handling of null values (vs NULL
values) passed as parameters to a stored proc.
I have always believed that the database handled NULL and null the
same. ...
|
by: =?Utf-8?B?Vmlua2k=?= |
last post by:
Hello Everyone,
I can successfully insert and update the oracle database by calling a
oracles stored proc from my .net code. This oracle stored proc is returning
some value. I cannot see that...
|
by: =?Utf-8?B?Vmlua2k=?= |
last post by:
Hello Everyone,
I can successfully insert and update the oracle database by calling a
oracles stored proc from my .net code. This oracle stored proc is returning
some value. I cannot see that...
|
by: Brad Pears |
last post by:
I am using vb.net 2005 and SQL server 2000. In my table I have a date field
of type "smalldatetime". In my vb application, the user may or may not enter
a date value into the appropriate text box....
|
by: bogdan |
last post by:
Hi,
I have a stored procedure that returns a single value. Example:
SELECT @RowCount = COUNT(*) FROM t WHERE
RETURN @RowCount
I created a data set, table adapter, and adapter's method...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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...
|
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,...
|
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...
|
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...
| |