If this is your first visit, be sure to
check out the
FAQ
by clicking the
link above. You may have to
register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.
System.InvalidCastException: Invalid cast from Int32 to DateTime. at System.Int32.System.IConvertible.ToDateTime(IFormatProvider provider) at System.Convert.ToDateTime(Object value) at System.Data.Common.DateTimeStorage.Set(Int32 record, Object value) at System.Data.DataColumn.set_Item(Int32 record, Object value)Couldn't store <0> in testdate Column. Expected type is DateTime.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentException: System.InvalidCastException: Invalid cast from Int32 to DateTime. at System.Int32.System.IConvertible.ToDateTime(IFormatProvider provider) at System.Convert.ToDateTime(Object value) at System.Data.Common.DateTimeStorage.Set(Int32 record, Object value) at System.Data.DataColumn.set_Item(Int32 record, Object value)Couldn't store <0> in testdate Column. Expected type is DateTime.
Source Error:
Line 160: AddInfo("testtwo") = "(New)"
Line 161: AddInfo("testthree") = "(New)"
Line 162: AddInfo("testdate") = "0/0/0000"
Line 163: Me.TestDataSet.testing.Rows.InsertAt(AddInfo, 0)
Line 164: Session("testDS") = TestDataSet
The code:
Code:
Private Sub btAdd_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btAdd.Click
Dim AddInfo As DataRow = Me.TestDataSet.testing.NewRow
AddInfo("testid") = "0"
AddInfo("testone") = "(New)"
AddInfo("testtwo") = "(New)"
AddInfo("testthree") = "(New)"
AddInfo("testdate") = "0/0/0000"
Me.TestDataSet.testing.Rows.InsertAt(AddInfo, 0)
Session("testDS") = TestDataSet
testGrid.EditItemIndex = 0
testGrid.DataBind()
End Sub
I'm still very new to asp.net stuff. can someone explain what I should do?
The DateTime structure's minimum date is 1/1/0000 12:00:00 AM
It really has a problem with you trying to set a date of 0/0/0000. If January is 1, and December is 12, what month is 0? How many months have 0 days?
This is like asking for February 32nd (although I think it rounds it up into March).
May I suggest you try this if you're looking to set a null date
VB Code:
AddInfo("testdate") = Nothing
'OR
AddInfo("testdate") = DBNull.Value
Unfortunately i am experiencing the same problem
But in my case all dates are valid dates.
One of the three dates is allowed to be DBNull;
The error occurs in both cases; DBNull or Valid Date.
I am using a .net generated table adapter.
I turned off the tags preventing user debugging
The error is occuring in mscorlib.dll
when the generated code is calling
System.Data.SqlClient.SqlDataAdapter Adapter.Update
Message "Failed to convert parameter value from a Int32 to a DateTime."
I am narrowing the problem down.
I replaced the stored procedure call with a prepared statement.
Now if I provide the date it works;
but if i provide a DBNull i get a meaningfull error
SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.
I suspect the reason i was getting the error with or without the date
when using the stored procedure is because the
@IsNull_completedDate datetime,
and / or
@Original_completedDate datetime,
is not being handled correctly by the 2.0 .NET framework
As a temporary workaround i am supplying 1/1/1900 as a date
had to modify my DTO to consider that date a null.
This problem is definately re-producable.
Need to re-register ASP.NET?
C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i
(Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)
DateTime parsing seems to be major issue that every developer runs into eh?
Why couldn't the world just agree on a standard format? hehe
BTW You can read about data types and their respective casting functions here:
http://www.codereference.com/book/vbnet_Types.aspx
Advertiser Disclosure:
Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.