Null values enter to SQL

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Movsum Zade

    #1

    Null values enter to SQL


    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:
    "SqlDateTim e 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.Ce lls(11).Control s(0), TextBox)
    If dateunl.Text = "" Then
    dateunloadnew = Nothing
    Else : dateunloadnew = dateunl.Text
    End If

    Dim r As Loadings._Dom_L oadingsRow
    r = Loadings2._Dom_ Loadings.FindBy id(key)

    r.DateUnload() = dateunloadnew

    SqlDataAdapter1 .Update(Loading s2)

    Thanks,

    Movsum

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
  • DudeGuy

    #2
    Re: Null values enter to SQL

    assgin DBNull in VB.NEt you will be fine.

    [color=blue]
    >-----Original Message-----
    >I do not know how in VB, but in C# you could
    >
    >if (dateunl.Text.E quals(string.Em pty)){
    > dateunloadnew = System.Data.Sql Types.SqlDateTi me.Null;
    >}
    >
    >Vaclav
    >
    >
    >"Movsum Zade" <mmzade@socarmo .az> wrote in message
    >news:%23LTKXnP VDHA.1896@TK2MS FTNGP12.phx.gbl ...[color=green]
    >>
    >> Hi,
    >>
    >> I have datagrid filled using SqlDataAdapter. One of the[/color][/color]
    fields is a date[color=blue][color=green]
    >> field which can be null.
    >>
    >> When I assign null value I receive the following error:
    >> "SqlDateTim e overflow. Must be between 1/1/1753[/color][/color]
    12:00:00 AM and[color=blue][color=green]
    >> 12/31/9999 11:59:59 PM."
    >>
    >> My code:
    >> Dim dateunl As TextBox
    >> dateunl = CType(e.Item.Ce lls(11).Control s(0),[/color][/color]
    TextBox)[color=blue][color=green]
    >> If dateunl.Text = "" Then
    >> dateunloadnew = Nothing
    >> Else : dateunloadnew = dateunl.Text
    >> End If
    >>
    >> Dim r As Loadings._Dom_L oadingsRow
    >> r = Loadings2._Dom_ Loadings.FindBy id(key)
    >>
    >> r.DateUnload() = dateunloadnew
    >>
    >> SqlDataAdapter1 .Update(Loading s2)
    >>
    >> Thanks,
    >>
    >> Movsum
    >>
    >> *** Sent via Developersdex http://www.developersdex.com[/color][/color]
    ***[color=blue][color=green]
    >> Don't just participate in USENET...get rewarded for it![/color]
    >
    >
    >.
    >[/color]

    Comment

    Working...