tinyint+invalid cast exception with DataReader
today i had faced a wired error in my DAL it was throwing an error invalid cast my code is like this:
int empid = reader.GetInt32(“EMPID”); //throws invalid cast..
i checked it with my database schema EMPID is tinyint. which is main cause of an error..
I had done R&D and come in to know that:
SQL SERVER Stored tinyint as 8bit[1byte] .so we can’t fetch it using getint32…so to fetch it i had changed my code to:
int empid = Convert.ToInt32(reader.GetBytes(“EMPID”)); //worked