Bit vs Tinyint type cast error

Posted by Murugavelmsc under C# on 10/1/2014 | Points: 10 | Views : 450 | Status : [Member] | Replies : 1
Hi Experts,

I have two tables.

In which one table has column as "rowheader" datatype bit,
another table has column as "rowheader" datatype tinyint,

In C# code,

int OutputColumnHeader;
OutputColumnHeader = (dr.GetBoolean(11) ? 1 : 0);

if we pass second table means it throws "not a valid cast" error.

Please help.

Murugavel S

Murugavel S


Posted by: Naveenhcl on: 10/1/2014 [Member] Starter | Points: 25


Whenever you are using same column name in multiple tables better to use the datatype also same. If you are using different datatypes then you may face this type of issues only and coming to your thread in your table1 your datatype is tinyint and in table2 that is byte. So, when you convert it into different format obviously you may got conversion issues. So, you must and should take care of that while converting one format information in to another format, using Convert function in SQL you may overcome this issue.

select Convert(yourdesireddatatype, yourfield);

Murugavelmsc, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response