Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2128
  • 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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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