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 3 8380
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
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
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! This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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,...
|
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.".
...
|
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...
|
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...
|
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...
|
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...
|
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
...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
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: 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: 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...
|
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...
|
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,...
|
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...
| |