Solved

How To: save Null values pass through storedproc parameters

Posted on 2004-10-07
3
809 Views
Last Modified: 2012-06-27
Private Function InsertEvaluation( _
        ByVal prmCustomerID As String, _
        ByVal prmID As String, _
        Optional ByVal prmSatisfaction As String = "", _
        Optional ByVal prmWillingToPay As String = "" _
        ) As Boolean

  Dim cmd As OleDbCommand = New OleDbCommand(sp, dbConn.Conn)
            cmd.CommandType = CommandType.StoredProcedure

...
...
            Dim CID As OleDbParameter = New OleDbParameter("p_ID", OleDbType.VarWChar)
             CID.Value = prmCustomerID
            cmd.Parameters.Add(pID)
...
..
end function

if i use
Private Function InsertEvaluation( _
        ByVal prmCustomerID As String, _
        ByVal prmID As String, _
        Optional ByVal prmSatisfaction As object= DBNull.value, _
        Optional ByVal prmWillingToPay As object= DBNull.value _
        ) As Boolean

i get a message that i have to use a constant value.,
0
Comment
Question by:Jerry_Pang
3 Comments
 
LVL 6

Assisted Solution

by:zulu_11
zulu_11 earned 40 total points
ID: 12246504
Private Function InsertEvaluation( _
        ByVal prmCustomerID As String, _
        ByVal prmID As String, _
        Optional ByVal prmSatisfaction As String = Convert.ToString( nothing ) , _
        Optional ByVal prmWillingToPay As String = Convert.ToString( nothing ) _
        ) As Boolean

try this
0
 
LVL 20

Assisted Solution

by:ihenry
ihenry earned 40 total points
ID: 12246623
Hi,

Overload the method would solve your problem,

    Private Function InsertEvaluation( _
            ByVal prmCustomerID As String, _
            ByVal prmID As String _
            ) As Boolean

        InsertEvaluation(prmCustomerID, prmID, DBNull.Value, DBNull.Value)
    End Function

    Private Function InsertEvaluation( _
            ByVal prmCustomerID As String, _
            ByVal prmID As String, _
            ByVal prmSatisfaction As Object, _
            ByVal prmWillingToPay As Object _
            ) As Boolean

    End Function

HTH
0
 
LVL 3

Accepted Solution

by:
skpatra earned 45 total points
ID: 12247271
Change the signature as

Private Function InsertEvaluation( _
        ByVal prmCustomerID As String, _
        ByVal prmID As String, _
        Optional ByVal prmSatisfaction As String = Nothing, _
        Optional ByVal prmWillingToPay As String = Nothing _
        ) As Boolean


Now, in the body add this:

If prmSatisfaction Is Nothing Then
    prmSatisfaction = DBNull.Value
End If

If prmWillingToPay Is Nothing Then
    prmWillingToPay = DBNull.Value
End If
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now