Solved

How To: save Null values pass through storedproc parameters

Posted on 2004-10-07
3
810 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
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 …
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

777 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