PC Review


Reply
Thread Tools Rate Thread

SqlDateTime overflow error inserting a null date into a nullable sql2000 datetime column using ado.net/vb.net, 1.1 framework

 
 
Chris
Guest
Posts: n/a
 
      10th Sep 2004
I'm trying to insert a null date into a nullable sql2000 datetime column,
but i'm getting this error:

An unhandled exception of type 'System.Data.SqlTypes.SqlTypeException'
occurred in system.data.dll

Additional information: SqlDateTime overflow. Must be between 1/1/1753
12:00:00 AM and 12/31/9999 11:59:59 PM.

See code below.

Any help is greatly appreciated!

Chris

-------START----------------------
Imports System.Data.SqlClient
MyFct(ByVal SomeDate As DateTime)
...
cmd.CommandText = "MyStoredProc"
cmd.Parameters.Add(New SqlParameter("@SomeDate", SqlDbType.DateTime, 8))
'IsDBNull(SomeDate) is True at this point (aka, #12:00:00 AM#).
cmd.Parameters("@SomeDate").Value = SomeDate
cn.Open()
cmd.ExecuteNonQuery() 'This line gives error (above).
end function
-----------------------------
SQL Server 2000 Stored Proc:
CREATE PROCEDURE MyStoredProc
@SomeDate datetime
AS
INSERT INTO MyTable (
SomeDate
)
VALUES (
@SomeDate
)
-----------------------------
SQL Server 2000 Partial Tbl Def:
CREATE TABLE [MyTable] (
....
[SomeDate] [datetime] NULL
)

-----------END------------------



 
Reply With Quote
 
 
 
 
Craig Yellick
Guest
Posts: n/a
 
      10th Sep 2004
You're running into the differences between the SqlServer versus .NET
definition of the datetime data type.

Your MyFct function accepts the parameter SomeDate as a datetime, and
I'll guess that you're sending the .NET value of "nothing" as a
parameter value. That's not the same as a SqlServer "null" value. You
get something for nothing with .NET datetime (sorry, could not resist
that one). Add the code fragment below, which converts the .NET
datetime into an actual null.

If SomeDate = DateTime.MinValue Then
cmd.Parameters("@SomeDate").Value = DBNull.Value
Else
cmd.Parameters("@SomeDate").Value = SomeDate
End If

-- Craig Yellick, Alto
www.altoConsulting.com
www.altoTraining.com

"Chris" <(E-Mail Removed)> wrote in message news:<C280d.105239$(E-Mail Removed)>...
> I'm trying to insert a null date into a nullable sql2000 datetime column,
> but i'm getting this error:
>
> An unhandled exception of type 'System.Data.SqlTypes.SqlTypeException'
> occurred in system.data.dll
>
> Additional information: SqlDateTime overflow. Must be between 1/1/1753
> 12:00:00 AM and 12/31/9999 11:59:59 PM.
>
> See code below.
>
> Any help is greatly appreciated!
>
> Chris
>
> -------START----------------------
> Imports System.Data.SqlClient
> MyFct(ByVal SomeDate As DateTime)
> ...
> cmd.CommandText = "MyStoredProc"
> cmd.Parameters.Add(New SqlParameter("@SomeDate", SqlDbType.DateTime, 8))
> 'IsDBNull(SomeDate) is True at this point (aka, #12:00:00 AM#).
> cmd.Parameters("@SomeDate").Value = SomeDate
> cn.Open()
> cmd.ExecuteNonQuery() 'This line gives error (above).
> end function
> -----------------------------
> SQL Server 2000 Stored Proc:
> CREATE PROCEDURE MyStoredProc
> @SomeDate datetime
> AS
> INSERT INTO MyTable (
> SomeDate
> )
> VALUES (
> @SomeDate
> )
> -----------------------------
> SQL Server 2000 Partial Tbl Def:
> CREATE TABLE [MyTable] (
> ...
> [SomeDate] [datetime] NULL
> )
>
> -----------END------------------

 
Reply With Quote
 
Chris
Guest
Posts: n/a
 
      12th Sep 2004
Craig,

Thanks! That was it indeed. I thought i'd already tried that, but i think i
was trying to do it in one line. Now i've got a function for all these.

Thanks again,

Chris


"Craig Yellick" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> You're running into the differences between the SqlServer versus .NET
> definition of the datetime data type.
>
> Your MyFct function accepts the parameter SomeDate as a datetime, and
> I'll guess that you're sending the .NET value of "nothing" as a
> parameter value. That's not the same as a SqlServer "null" value. You
> get something for nothing with .NET datetime (sorry, could not resist
> that one). Add the code fragment below, which converts the .NET
> datetime into an actual null.
>
> If SomeDate = DateTime.MinValue Then
> cmd.Parameters("@SomeDate").Value = DBNull.Value
> Else
> cmd.Parameters("@SomeDate").Value = SomeDate
> End If
>
> -- Craig Yellick, Alto
> www.altoConsulting.com
> www.altoTraining.com
>
> "Chris" <(E-Mail Removed)> wrote in message

news:<C280d.105239$(E-Mail Removed)>...
> > I'm trying to insert a null date into a nullable sql2000 datetime

column,
> > but i'm getting this error:
> >
> > An unhandled exception of type 'System.Data.SqlTypes.SqlTypeException'
> > occurred in system.data.dll
> >
> > Additional information: SqlDateTime overflow. Must be between 1/1/1753
> > 12:00:00 AM and 12/31/9999 11:59:59 PM.
> >
> > See code below.
> >
> > Any help is greatly appreciated!
> >
> > Chris
> >
> > -------START----------------------
> > Imports System.Data.SqlClient
> > MyFct(ByVal SomeDate As DateTime)
> > ...
> > cmd.CommandText = "MyStoredProc"
> > cmd.Parameters.Add(New SqlParameter("@SomeDate", SqlDbType.DateTime,

8))
> > 'IsDBNull(SomeDate) is True at this point (aka, #12:00:00 AM#).
> > cmd.Parameters("@SomeDate").Value = SomeDate
> > cn.Open()
> > cmd.ExecuteNonQuery() 'This line gives error (above).
> > end function
> > -----------------------------
> > SQL Server 2000 Stored Proc:
> > CREATE PROCEDURE MyStoredProc
> > @SomeDate datetime
> > AS
> > INSERT INTO MyTable (
> > SomeDate
> > )
> > VALUES (
> > @SomeDate
> > )
> > -----------------------------
> > SQL Server 2000 Partial Tbl Def:
> > CREATE TABLE [MyTable] (
> > ...
> > [SomeDate] [datetime] NULL
> > )
> >
> > -----------END------------------



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
can someone explain this nullable datetime error to me Peted Microsoft C# .NET 2 27th Oct 2008 01:43 AM
SQLDateTime Overflow inserting DateTime that is Nothing Charles Law Microsoft VB .NET 24 27th Feb 2008 04:36 AM
Millisecond values missing when inserting datetime into datetime column of sql Server Manikandan Microsoft C# .NET 4 18th Jul 2007 09:59 PM
SQLDateTime Overflow error (ASP.Net 2.0 with SQL Server 2005) Randy Smith Microsoft ASP .NET 0 19th Apr 2007 04:54 AM
Adding a nullable datetime column to a datatable does not work GG Microsoft C# .NET 5 22nd Jul 2006 10:30 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:26 AM.