One sleazy way to do it is just sneak around the datatype conversion code
(the source of the exception) by indexing the row instead of referring to the
column property:
dr("CloseDate") = DbNull.Value
I have difficulties with this as well, and if there is a better way to
handle it, I don't know it.
Alternately, if your problem is validating and/or translating user entry
into a bound textbox on a windows form, then you can declare at the top of
your forms class:
Private WithEvents MyBinding As Binding
then copy the datetime textbox binding to it in, say, form Load:
MyBinding = MyTextBox.DataBindings.Item("Text")
and finally, handle the Format and Parse events for this binding:
Private Sub MyBinding_Format(ByVal sender As Object, ByVal e As
System.Windows.Forms.ConvertEventArgs) Handles MyBinding.Format
If (e.DesiredType Is GetType(System.String)) Then
If (e.Value Is System.DBNull.Value) Then
e.Value = ""
Else
e.Value = CType(e.Value, DateTime).ToString("d")
End If
End If
End Sub
Private Sub MyBinding_Parse(ByVal sender As Object, ByVal e As
System.Windows.Forms.ConvertEventArgs) Handles MyBinding.Parse
If (e.DesiredType Is GetType(DateTime)) Then
If (e.Value = "") Then
e.Value = System.DBNull.Value
Else
Try
e.Value = DateTime.Parse(e.Value)
Catch ex As FormatException
MessageBox.Show("The value '" & e.Value & "' is not a
recognizable date.")
End Try
End If
End If
End Sub
And if it's ASP code you're after, then you need someone else...
Good luck,
Mark