System.Data.SqlTypes.SqlTypeException:

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mike Albanese

    #1

    System.Data.SqlTypes.SqlTypeException:

    I am building an ASP.Net application with VB.Net. I have
    several date fields in my form and some of them are
    optional. If ther is no data in the form field i set the
    sql parameter to dbnull.value. Still the insert bombs out.
    The error i am getting is

    System.Data.Sql Types.SqlTypeEx ception: SqlDateTime
    overflow. Must be between 1/1/1753 12:00:00 AM and
    12/31/9999 11:59:59 PM

    Any insights would be apprecaited.

    Thanks,

    Mike

  • Trajero

    #2
    System.Data.Sql Types.SqlTypeEx ception:

    Do you have your fields in your database set to accept
    null values?[color=blue]
    >-----Original Message-----
    >I am building an ASP.Net application with VB.Net. I have
    >several date fields in my form and some of them are
    >optional. If ther is no data in the form field i set the
    >sql parameter to dbnull.value. Still the insert bombs[/color]
    out.[color=blue]
    >The error i am getting is
    >
    >System.Data.Sq lTypes.SqlTypeE xception: SqlDateTime
    >overflow. Must be between 1/1/1753 12:00:00 AM and
    >12/31/9999 11:59:59 PM
    >
    >Any insights would be apprecaited.
    >
    >Thanks,
    >
    >Mike
    >
    >.
    >[/color]

    Comment

    • Tian Min Huang

      #3
      RE: System.Data.Sql Types.SqlTypeEx ception:

      Hi Mike,

      Thanks for your post. In addition to Trajero's suggestion, I'd like to
      check the value of DateTime field you attempting to insert to database.
      Please make sure either SqlDateTime value is a valid value between 1/1/1753
      and 12/31/9999, or it is assigned as SqlDateTime.Nul l.

      I look forward to your response.

      Have a nice day!

      Regards,

      HuangTM
      Microsoft Online Partner Support
      MCSE/MCSD

      Get Secure! -- www.microsoft.com/security
      This posting is provided "as is" with no warranties and confers no rights.

      Comment

      • Michael Albanese

        #4
        RE: System.Data.Sql Types.SqlTypeEx ception:

        Hello and thanks for your replies.

        The SQL database fields are of type datatime and are set to accept null
        values.

        The value of the form field is not set to NULL as i had thought, but to
        #1/1/0001#. Once I realized this i was able to write the function below
        that would test the Form value and conditionally set the SQL parameter
        value.

        I have it working now. Thanks for your help.

        Michael

        Here is the cinction i wrote:

        Public Function chkDateParam(By Val d As Date, ByRef sqlParam As
        SqlParameter)
        Try
        If d = System.DateTime .MinValue Then
        sqlParam.Value = DBNull.Value
        Else
        sqlParam.Value = d
        End If

        Catch ex As NullReferenceEx ception

        'if the field is blank, str will = null. so set the param to
        null too!
        sqlParam.Value = DBNull.Value

        End Try
        End Function


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

        Comment

        Working...