Updating DateTime Value with DBNull

I'm trying to update a form that has a StartDate and EndDate column.  Neither of these are required fields and I can't figure out how to update with a null value.  Here's what I have:

        Dim prmStart As New SqlParameter("@Date_Start", SqlDbType.SmallDateTime)

        If Len(txtStartDate.Text) > 0 Then
            prmStart.Value = txtStartDate.Text
        Else
            prmStart.Value = DBNull.Value
        End If

This has to be easy but I'm stuck.

Thanks in advance,

N
stretch73Asked:
Who is Participating?
 
stretch73Connect With a Mentor Author Commented:
I figured it out, this function works:

    Public Shared Function SetDBNull(ByVal dtOrigDate) As DateTime

        Dim dtNull As SqlDateTime = SqlDateTime.Null

        If (dtOrigDate = "") Then
            SetDBNull = dtNull
        Else
            SetDBNull = DateTime.Parse(dtOrigDate)
        End If

        Return SetDBNull
    End Function

You just have to pass in whatever's in the textbox
0
 
surajgupthaCommented:
You are stuck with ?? Compile error/ Runtime error? If so what is the error?
0
 
Vee_ModCommented:
Closed, 500 points refunded.
Vee_Mod
Community Support Moderator
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.