Null values enter to SQL

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
 
D

DudeGuy

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





.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top