Updating DateTime Value with DBNull

Posted on 2007-10-04
Last Modified: 2013-11-07
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
            prmStart.Value = DBNull.Value
        End If

This has to be easy but I'm stuck.

Thanks in advance,

Question by:stretch73
    LVL 21

    Expert Comment

    You are stuck with ?? Compile error/ Runtime error? If so what is the error?

    Accepted Solution

    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
                SetDBNull = DateTime.Parse(dtOrigDate)
            End If

            Return SetDBNull
        End Function

    You just have to pass in whatever's in the textbox
    LVL 1

    Expert Comment

    Closed, 500 points refunded.
    Community Support Moderator

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    Problem to Popup 37 63
    Change to event 1 50
    Required permissions cannot be acquired 6 24
    Calculating a BCC (Xor) for a message 13 25
    More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    755 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

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now