• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 666
  • Last Modified:

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
0
stretch73
Asked:
stretch73
1 Solution
 
surajgupthaCommented:
You are stuck with ?? Compile error/ Runtime error? If so what is the error?
0
 
stretch73Author 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
 
Vee_ModCommented:
Closed, 500 points refunded.
Vee_Mod
Community Support Moderator
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now