• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2141
  • Last Modified:

Specified cast is not valid tinyint to int

myobj.Intproperty = myReader.GetInt32(myDataRecord.GetOrdinal("tinyintfield"))

Intproperty is a property in a class and its datatype is int
tinyintfield is a field in the table and its datatype is tinyint

Error message : - Specified cast is not valid.

Any thoughts
0
PradeepYadhav
Asked:
PradeepYadhav
  • 2
  • 2
1 Solution
 
Gautham JanardhanCommented:
myReader[myDataRecord.GetOrdinal("tinyintfield")].ToString() and see what the data is maybe a null value or something
0
 
PradeepYadhavAuthor Commented:
No they dont contain null.
0
 
Gautham JanardhanCommented:
what does this give

myReader[myDataRecord.GetOrdinal("tinyintfield")].ToString()
0
 
PradeepYadhavAuthor Commented:
if i convert it to int in the stored proc then it works fine.

select convert (int,tinyintfield) from table
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now