Solved

How To: save Null values pass through storedproc parameters

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Create a Dropdown list with sub group 10 43
CSS question 16 63
SSIS Column mapping 5 41
Delete command SQLdatasource in asp.net, vb 2 21
Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

739 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