Casting tinyint and smalling columns

J

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
 
L

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.)
 

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

Members online

No members online now.

Forum statistics

Threads
474,141
Messages
2,570,818
Members
47,367
Latest member
mahdiharooniir

Latest Threads

Top