Null values enter to SQL

  • Thread starter Thread starter Movsum Zade
  • Start date Start date
M

Movsum Zade

Hi,

I have datagrid filled using SqlDataAdapter. One of the fields is a date
field which can be null.

When I assign null value I receive the following error:
"SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and
12/31/9999 11:59:59 PM."

My code:
Dim dateunl As TextBox
dateunl = CType(e.Item.Cells(11).Controls(0), TextBox)
If dateunl.Text = "" Then
dateunloadnew = Nothing
Else : dateunloadnew = dateunl.Text
End If

Dim r As Loadings._Dom_LoadingsRow
r = Loadings2._Dom_Loadings.FindByid(key)

r.DateUnload() = dateunloadnew

SqlDataAdapter1.Update(Loadings2)

Thanks,

Movsum
 
assgin DBNull in VB.NEt you will be fine.

-----Original Message-----
I do not know how in VB, but in C# you could

if (dateunl.Text.Equals(string.Empty)){
dateunloadnew = System.Data.SqlTypes.SqlDateTime.Null;
}

Vaclav





.
 
Back
Top