Solved

How To: save Null values pass through storedproc parameters

Posted on 2004-10-07
3
814 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Quiz: What Do These Organizations Have In Common?

Hint: Their teams ended up taking quizzes, too.

Question has a verified solution.

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

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

626 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