473,320 Members | 2,029 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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.SqlParameter

pParms(0) = New SqlClient.SqlParameter("@ID", miID)
pParms(1) = New SqlClient.SqlParameter("@VendorID",
miVendorID)
pParms(2) = New SqlClient.SqlParameter("@StatusID",
miStatusID)
pParms(3) = New SqlClient.SqlParameter("@PONumber",
msPONumber)
pParms(4) = New SqlClient.SqlParameter("@Date",
mdPODate)
pParms(5) = New SqlClient.SqlParameter("@ContactName",
msContactName)
pParms(6) = New SqlClient.SqlParameter
("@ContactPhone", msContactPhone)
pParms(7) = New SqlClient.SqlParameter("@Comment",
msComment)
pParms(8) = New SqlClient.SqlParameter("@CreatedByID",
miCreatedByID)
pParms(9) = New SqlClient.SqlParameter
("@ModifiedByID", miModifiedByID)

Try
'perform insert
If miID = 0 Then
miID = SqlHelper.ExecuteScalar(msConnectionString,
CommandType.StoredProcedure, "p_PurchaseOrder_Insert",
pParms)
Else
'perform update
SqlHelper.ExecuteNonQuery(msConnectionString,
CommandType.StoredProcedure, "p_PurchaseOrder_Update",
pParms)
End If
Catch ex As Exception
Save = "Duplicate"
End Try
End Function
Jul 19 '05 #1
3 8377
You need to use "nothing" insted of "null" in .net

"Brian" <bs********@pdspc.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.SqlParameter

pParms(0) = New SqlClient.SqlParameter("@ID", miID)
pParms(1) = New SqlClient.SqlParameter("@VendorID",
miVendorID)
pParms(2) = New SqlClient.SqlParameter("@StatusID",
miStatusID)
pParms(3) = New SqlClient.SqlParameter("@PONumber",
msPONumber)
pParms(4) = New SqlClient.SqlParameter("@Date",
mdPODate)
pParms(5) = New SqlClient.SqlParameter("@ContactName",
msContactName)
pParms(6) = New SqlClient.SqlParameter
("@ContactPhone", msContactPhone)
pParms(7) = New SqlClient.SqlParameter("@Comment",
msComment)
pParms(8) = New SqlClient.SqlParameter("@CreatedByID",
miCreatedByID)
pParms(9) = New SqlClient.SqlParameter
("@ModifiedByID", miModifiedByID)

Try
'perform insert
If miID = 0 Then
miID = SqlHelper.ExecuteScalar(msConnectionString,
CommandType.StoredProcedure, "p_PurchaseOrder_Insert",
pParms)
Else
'perform update
SqlHelper.ExecuteNonQuery(msConnectionString,
CommandType.StoredProcedure, "p_PurchaseOrder_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********@pdspc.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.SqlParameter

pParms(0) = New SqlClient.SqlParameter("@ID", miID)
pParms(1) = New SqlClient.SqlParameter("@VendorID",
miVendorID)
pParms(2) = New SqlClient.SqlParameter("@StatusID",
miStatusID)
pParms(3) = New SqlClient.SqlParameter("@PONumber",
msPONumber)
pParms(4) = New SqlClient.SqlParameter("@Date",
mdPODate)
pParms(5) = New SqlClient.SqlParameter("@ContactName",
msContactName)
pParms(6) = New SqlClient.SqlParameter
("@ContactPhone", msContactPhone)
pParms(7) = New SqlClient.SqlParameter("@Comment",
msComment)
pParms(8) = New SqlClient.SqlParameter("@CreatedByID",
miCreatedByID)
pParms(9) = New SqlClient.SqlParameter
("@ModifiedByID", miModifiedByID)

Try
'perform insert
If miID = 0 Then
miID = SqlHelper.ExecuteScalar(msConnectionString,
CommandType.StoredProcedure, "p_PurchaseOrder_Insert",
pParms)
Else
'perform update
SqlHelper.ExecuteNonQuery(msConnectionString,
CommandType.StoredProcedure, "p_PurchaseOrder_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
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...
0
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...
0
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,...
7
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.". ...
6
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...
1
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...
0
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...
4
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...
1
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 ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.