How To assign null values in MySql using VB.NET

fireBand picture fireBand · Mar 5, 2010 · Viewed 35.3k times · Source

I am not sure why VB makes everything such a pain. I have a fields which stores the date and time in the format required to store in MySQL database

 Dim AppDate As String = String.Empty
      If Not String.IsNullOrEmpty(Me.AppDate.Text.Trim) Then
         AppDate = Format(CDate(Me.AppDate.Text), "yyyy-MM-dd h:mm:ss")
      Else
        //Need to assign a null value to AppDate 
      End If

Now I need to assign the AppDate to NUll like DBNull, but I am not able to do it directly. If I change AppDate to Date then I am not getting the required format.

Any help is appreciated .

Thanks in Advance.

Answer

Dan picture Dan · Mar 5, 2010

AppDate = Nothing should work, you could also use DateTime.MinValue and update your business logic to treat it appropriately.