|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
"Invalid cast from 'Int32' to 'DateTime'."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? Sharat Koya wrote:
Show quote > Hi I have a Visual Studio .NET Generated DataSet from SQL servers using the Turns out that it was because I slightly modified my select stored proc> 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? > > > > 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. |
|||||||||||||||||||||||