Click here to Skip to main content
15,886,787 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
public Int16 UserTypeID { get; set; }
us.UserTypeID = reader.GetInt16((Int16)reader["UserTypeID"]); plz help me
Posted
Comments
ravikhoda 14-Mar-14 6:36am    
did you check what value your reader is getting from the database? if is integer or not.
satheeshkumar chinnadurai 14-Mar-14 6:37am    
tinyint

1 solution

Try:
C#
us.UserTypeID = (Int16)reader["UserTypeID"];
 
Share this answer
 
Comments
satheeshkumar chinnadurai 14-Mar-14 6:41am    
same error i am getting
OriginalGriff 14-Mar-14 6:47am    
OK - you need to look at exactly what you are getting back.
You say the data type is tinyint - so casting to int16 shoudln't be a problem, unless the value returned is null - have you set the DB column to "allow nulls" "No"?
If not, that could be the problem. Try this:
object o = reader["UserTypeID"];
if (o == DbNUll.Value)
{
// Log or report the problem - I don't know what system you are working with, so I can't tell you exactly
}
else
{
us.UserTypeID = (Int16) o;
}

If that doesn't help, put a breakpoint on the "if" and look at what is in "o" with the debugger.
satheeshkumar chinnadurai 14-Mar-14 6:56am    
Specified cast is not valid. again i am getting same error this line us.UserTypeID = (Int16) o;
OriginalGriff 14-Mar-14 7:25am    
So what does the debugger say is in the variable "o"?
satheeshkumar chinnadurai 14-Mar-14 7:43am    
i cann't understand

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900