All Forums Connectivity
tekriewa 8 posts Joined 04/13
22 Jul 2014
Cannot convert from Db.DateTimeOffset to Td.TimeStampWithZone

I am attempting to execute a parametrized non-query SQL command using TdCommand.ExecuteNonQuery().  The parameter in question is DbType.DateTimeOffset and TdType.TimestampWithZone; the parameter value was generated using DateTime.Now and appears to be completely defined (as verified via the Visual Studio debugger).  When I reach my ExecuteNonQuery() statement, I receive a System.InvalidCastException with message "Cannot convert to Timestamp with Time Zone".  The command text, for what it's worth, is simply: "INSERT INTO DateTimeOffsetTable (DateTimeOffsetVal) VALUES(?);".  
The Teradata Configuring Parameters and Parameter Data Types page suggests that DateTimeOffset should map to TimeStampWithZone; however it also indicates that inference from DateTime2 is not supported.  Not sure if it matters, but the Date/Time data types description provided by Microsoft ( bb675168(v=vs.110).aspx), however, says "The datetimeoffset data type has all the features of datetime2 with an additional time zone offset."  Would this affect the conversion?  If not, any suggestions how to remedy the issue?

NetFx 346 posts Joined 09/06
24 Jul 2014

You wrote

the parameter value was generated using DateTime.Now 

change it to DateTimeOffset.Now.

You must sign in to leave a comment.