473,856 Members | 1,593 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SQLHelper not allowing me to pass Null paramter

I am trying to pass a null value into a stored procedure
so that it can save the data. I am using Microsoft's
SQLHelper dll to do this. My example code is below. How
do I pass in a null value as a parameter? For example, in
the code below, miVendorID is declared as an Object. The
save attempt fails if the object has not been populated
(for example, the person choose not to select a vendor
from the dropdown list) I have the same problem for both
numeric and string fields.

Public Function Save() As String

Dim pParms(9) As SqlClient.SqlPa rameter

pParms(0) = New SqlClient.SqlPa rameter("@ID", miID)
pParms(1) = New SqlClient.SqlPa rameter("@Vendo rID",
miVendorID)
pParms(2) = New SqlClient.SqlPa rameter("@Statu sID",
miStatusID)
pParms(3) = New SqlClient.SqlPa rameter("@PONum ber",
msPONumber)
pParms(4) = New SqlClient.SqlPa rameter("@Date" ,
mdPODate)
pParms(5) = New SqlClient.SqlPa rameter("@Conta ctName",
msContactName)
pParms(6) = New SqlClient.SqlPa rameter
("@ContactPhone ", msContactPhone)
pParms(7) = New SqlClient.SqlPa rameter("@Comme nt",
msComment)
pParms(8) = New SqlClient.SqlPa rameter("@Creat edByID",
miCreatedByID)
pParms(9) = New SqlClient.SqlPa rameter
("@ModifiedByID ", miModifiedByID)

Try
'perform insert
If miID = 0 Then
miID = SqlHelper.Execu teScalar(msConn ectionString,
CommandType.Sto redProcedure, "p_PurchaseOrde r_Insert",
pParms)
Else
'perform update
SqlHelper.Execu teNonQuery(msCo nnectionString,
CommandType.Sto redProcedure, "p_PurchaseOrde r_Update",
pParms)
End If
Catch ex As Exception
Save = "Duplicate"
End Try
End Function
Jul 19 '05 #1
3 8413
You need to use "nothing" insted of "null" in .net

"Brian" <bs********@pds pc.com> wrote in message
news:0b******** *************** *****@phx.gbl.. .
I am trying to pass a null value into a stored procedure
so that it can save the data. I am using Microsoft's
SQLHelper dll to do this. My example code is below. How
do I pass in a null value as a parameter? For example, in
the code below, miVendorID is declared as an Object. The
save attempt fails if the object has not been populated
(for example, the person choose not to select a vendor
from the dropdown list) I have the same problem for both
numeric and string fields.

Public Function Save() As String

Dim pParms(9) As SqlClient.SqlPa rameter

pParms(0) = New SqlClient.SqlPa rameter("@ID", miID)
pParms(1) = New SqlClient.SqlPa rameter("@Vendo rID",
miVendorID)
pParms(2) = New SqlClient.SqlPa rameter("@Statu sID",
miStatusID)
pParms(3) = New SqlClient.SqlPa rameter("@PONum ber",
msPONumber)
pParms(4) = New SqlClient.SqlPa rameter("@Date" ,
mdPODate)
pParms(5) = New SqlClient.SqlPa rameter("@Conta ctName",
msContactName)
pParms(6) = New SqlClient.SqlPa rameter
("@ContactPhone ", msContactPhone)
pParms(7) = New SqlClient.SqlPa rameter("@Comme nt",
msComment)
pParms(8) = New SqlClient.SqlPa rameter("@Creat edByID",
miCreatedByID)
pParms(9) = New SqlClient.SqlPa rameter
("@ModifiedByID ", miModifiedByID)

Try
'perform insert
If miID = 0 Then
miID = SqlHelper.Execu teScalar(msConn ectionString,
CommandType.Sto redProcedure, "p_PurchaseOrde r_Insert",
pParms)
Else
'perform update
SqlHelper.Execu teNonQuery(msCo nnectionString,
CommandType.Sto redProcedure, "p_PurchaseOrde r_Update",
pParms)
End If
Catch ex As Exception
Save = "Duplicate"
End Try
End Function

Jul 19 '05 #2
Brian,
Have you tried setting the appropriate parameter to DBNull.Value vs.
null? This is what is passed back from a database for a null value. Also,
are you sure that your stored procedure will accept a null parameter? Try
testing it in QueryAnalyzer to see.

Ron Allen
"Brian" <bs********@pds pc.com> wrote in message
news:0b******** *************** *****@phx.gbl.. .
I am trying to pass a null value into a stored procedure
so that it can save the data. I am using Microsoft's
SQLHelper dll to do this. My example code is below. How
do I pass in a null value as a parameter? For example, in
the code below, miVendorID is declared as an Object. The
save attempt fails if the object has not been populated
(for example, the person choose not to select a vendor
from the dropdown list) I have the same problem for both
numeric and string fields.

Public Function Save() As String

Dim pParms(9) As SqlClient.SqlPa rameter

pParms(0) = New SqlClient.SqlPa rameter("@ID", miID)
pParms(1) = New SqlClient.SqlPa rameter("@Vendo rID",
miVendorID)
pParms(2) = New SqlClient.SqlPa rameter("@Statu sID",
miStatusID)
pParms(3) = New SqlClient.SqlPa rameter("@PONum ber",
msPONumber)
pParms(4) = New SqlClient.SqlPa rameter("@Date" ,
mdPODate)
pParms(5) = New SqlClient.SqlPa rameter("@Conta ctName",
msContactName)
pParms(6) = New SqlClient.SqlPa rameter
("@ContactPhone ", msContactPhone)
pParms(7) = New SqlClient.SqlPa rameter("@Comme nt",
msComment)
pParms(8) = New SqlClient.SqlPa rameter("@Creat edByID",
miCreatedByID)
pParms(9) = New SqlClient.SqlPa rameter
("@ModifiedByID ", miModifiedByID)

Try
'perform insert
If miID = 0 Then
miID = SqlHelper.Execu teScalar(msConn ectionString,
CommandType.Sto redProcedure, "p_PurchaseOrde r_Insert",
pParms)
Else
'perform update
SqlHelper.Execu teNonQuery(msCo nnectionString,
CommandType.Sto redProcedure, "p_PurchaseOrde r_Update",
pParms)
End If
Catch ex As Exception
Save = "Duplicate"
End Try
End Function

Jul 19 '05 #3
Wow!! It worked! It's ALIVE!! Using DBNull.value appears to allow
the SQLHelper DLL know to pass in a null value for both string and
numeric data. Thanks a lot Ron!

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 19 '05 #4

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

Similar topics

2
4397
by: Neal | last post by:
I need to know how to pass a parameter from PERL to an XSLT when using that XSLT to transform XML. For instance, I'd like to pass a paramter that I retrieve from the queryString and pass it into XSLT which will create my HTML. Here's what I have for the basic transformation: #!/usr/local/bin/perl use XML::XSLT;/
0
1655
by: Peter Lin | last post by:
Dear all, I am using Microsoft.ApplicationBlocks.Data, for one thing I am not quite sure. Is the following static SqlHelper ExecuteReader method from source codes not thread saft in multithread environment? Do we need to use lock or monitor to protect our data in the static method in multithread environment? Do the following codes have the reentry problem in multithread environment because I have threads that use SqlHelper to get data...
0
1655
by: Rajesh Kumar | last post by:
Hi Gregory Thanks for your answer. I did not see any attached file so I copied your text into a text file and named it compiler.bat Checked the wrapped lines and runned the file. It said Dataset, Datareader and some other things are not defined. So I entered the : Imports Microsoft.ApplicationBlocks.Data Imports system Imports system.data Imports System.Data.SqlClient
7
12025
by: Neven Klofutar | last post by:
Hi, I have a problem with SqlHelper.ExecuteScalar ... When I try to execute SqlHelper.ExecuteScalar I get this message: "System.InvalidCastException: Object must implement IConvertible.". Help ... Thanx, Neven
6
383
by: Brian | last post by:
I am trying to pass a null value into a stored procedure so that it can save the data. I am using Microsoft's SQLHelper dll to do this. My example code is below. How do I pass in a null value as a parameter? For example, in the code below, miVendorID is declared as an Object. The save attempt fails if the object has not been populated (for example, the person choose not to select a vendor from the dropdown list) I have the same...
1
1817
by: jacobyv | last post by:
hi i created survey.asp which displays the survey passed through the name paramter in the url. it works fine if i open the page like this. http://url/survey.asp?name=survey1 but now i would like to include survey.asp in a different asp file, let's call it main.asp, and display several surveys.
0
2107
by: raghuraman_ace | last post by:
Hi i have started a webservice wich has a webmethod with parameters using literal encoding & encoded encoding . The webservice is compiled successfully . But i don know how to pass the parameters that satisfy these encodings . My web method is ---------------------------------------------
4
2132
by: John F | last post by:
Hello All, What is the consensus on using sqlhelper or not using sqlhelper when calling stored procedures? We're trying to go with a standard for our projects and personally I prefer not using sqlhelper, but some here do. I'm just curious if there are any good arguments for or against it... Thanks,
1
2942
by: John A Grandy | last post by:
I would like to pass a DataRow column value to a method that accepts an object parameter : MyMethod( object value ) {} However, a problem occurs if the column value is DBNull.Value MyMethod( DataRow );
0
9916
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
9762
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
11057
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
10696
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9531
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7932
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
5761
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
5958
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4174
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.