Quantcast
Channel: Visual C# forum
Viewing all articles
Browse latest Browse all 31927

GetDateTime and SQL Server 2008 data type

$
0
0
I am using a DbDataReader to call a stored procedure, this stored procedure pulls back a column whose Data type is "Time" in SQL server 2008.  The stored procedure is just a trivial select statement.

However when I try to do this:

int TimeOrdinal = dr.GetOrdinal("MyTimeValue");

 while (dr.Read())
            {
               dr.GetDateTime(TimeOrdinal)
            }

I receive the error:

Specified cast is not valid. body {font-family:"Verdana";font-weight:normal;font-size: .7em;color:black;} p {font-family:"Verdana";font-weight:normal;color:black;margin-top: -5px} b {font-family:"Verdana";font-weight:bold;color:black;margin-top: -5px} H1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red } H2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon } pre {font-family:"Lucida Console";font-size: .9em} .marker {font-weight: bold; color: black;text-decoration: none;} .version {color: gray;} .error {margin-bottom: 10px;} .expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:hand; }

Specified cast is not valid.

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.InvalidCastException: Specified cast is not valid.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[InvalidCastException: Specified cast is not valid.]
System.Data.SqlClient.SqlBuffer.get_DateTime() +4833622

Now this to me doesn't make sense. To you get time values as integers or DateTimes?

Viewing all articles
Browse latest Browse all 31927

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>