"Invalid cast from 'Int32' to 'DateTime'."

G

Guest

Hi I have a Visual Studio .NET Generated DataSet from SQL servers using the
wizard.

I have a particular table with the column that stores when the row in the
table was last updated.

I then have the following code...

foreach (DataRow object in DataSet.DataTable)
{
object.LastUpdated = DateTime.Now;
}

try {
ObjectDataAdapter.Update(DataSet.DataTable)
}
catch (System.InvalidCastException ex)
{
.... read data. key/value pairs for debug
}


for some reason when I try to update the SQL 05 database I get the following
error:

"Invalid cast from 'Int32' to 'DateTime'."

this is a InvalidCastException but the key/value pairs within the Data
property of the exception are empty and the TargetSite says

{Void UpdatedRowStatusErrors(System.Data.Common.RowUpdatedEventArgs,
BatchCommandInfo[], Int32)}


Both regional settings and timezones are both the same on the server and the
client that has VS.NET on it.

Can anyone help?
 
S

Sharat Koya

Sharat said:
Hi I have a Visual Studio .NET Generated DataSet from SQL servers using the
wizard.

I have a particular table with the column that stores when the row in the
table was last updated.

I then have the following code...

foreach (DataRow object in DataSet.DataTable)
{
object.LastUpdated = DateTime.Now;
}

try {
ObjectDataAdapter.Update(DataSet.DataTable)
}
catch (System.InvalidCastException ex)
{
... read data. key/value pairs for debug
}


for some reason when I try to update the SQL 05 database I get the following
error:

"Invalid cast from 'Int32' to 'DateTime'."

this is a InvalidCastException but the key/value pairs within the Data
property of the exception are empty and the TargetSite says

{Void UpdatedRowStatusErrors(System.Data.Common.RowUpdatedEventArgs,
BatchCommandInfo[], Int32)}


Both regional settings and timezones are both the same on the server and the
client that has VS.NET on it.

Can anyone help?

Turns out that it was because I slightly modified my select stored proc
to include an if statment. For some reason ADO.NET and VS.NET couldn't
auto gen the code correctly.

I modfied it from the simple

select * from tablex where id = @id

to

if @indexType = 1
begin
select * from tablex where id = @id
end
else
begin
select * from tablex where id2 = @id
end


So effectively I added an extra parameter that allowed me to choose
which index to use to look up the object.
 

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

Top