TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
shanem
NA
1
0
Getting Integer Values from DataReader
Nov 17 2003 2:30 PM
How can I get C# to pull back a value from a datareader that is a datatype of int in a sql database. The following code returns an InvalidCastException error: SqlCommand cmd = new SqlCommand("SELECT name, xtype, length, colstat FROM syscolumns WHERE id = (SELECT id FROM sysobjects WHERE name = '" + Table + "')", cn); SqlDataReader dr = cmd.ExecuteReader(); SqlParameter prm; long xtype = 0; while (dr.Read()) { xtype = (long)dr.GetSqlInt64(1); } xtype in syscolumns in SQL is a datatype of tinyint. I have tried using dr.GetSqlInt16, GetSqlInt32, and GetSqlInt64 as well as throwing it into a variable declared as integer, short, and long. I've also tried using dr.GetInt16 (instead of GetSqlInt16), GetInt32, and GetInt64...same error. It seems that C# doesn't like anything except strings and objects when it comes to the datareader and I need to be able to get an integer value back. Thoughts?
Reply
Answers (
1
)
using Windows Fax Service in C#
c# and VB.NET's Implements