Home All Groups Group Topic Archive Search About

Casting tinyint and smalling columns



Author
17 May 2006 3:56 AM
Jacob F.
Hello all,

I'm working on an application that uses a DbDataReader to retrieve
information from a SQL Server 2005 column, then put that data into object
variables.  My code looks like this:

value = (int)dbReader["value"]

For column types of int, this works fine.  However, for tinyint or smallint,
I get an invalid cast error.

Is there a way to make this work?

Thanks,
Jacob

Author
17 May 2006 5:33 AM
Luke Zhang [MSFT]
Hello Jacob,

For .NET related issue, you may post in microsoft.public.dotnet.general or
microsoft.public.dotnet.framework.adonet.

Regarding the question, you may try DbDataReader's GetInt32() method to
convert a column's value to integer.

Regards,

Luke Zhang
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)

AddThis Social Bookmark Button