Reputation: 3243
I have a simple piece of code
bool retrievalAttempted = Convert.ToBoolean(reader.GetByte(1));
where column 1
is of type BIT NOT NULL
and yet I keep getting the exception
System.InvalidCastException: Specified cast is not valid.
What am I doing wrong here?
Upvotes: 1
Views: 623
Reputation: 3
A bit is different than a byte !
Look at this link for sql server types vs .net types SQL Server Data Type Mappings
Upvotes: 0
Reputation: 460238
If it's a bit
-column you have to use reader.GetBoolean
:
bool retrievalAttempted = reader.GetBoolean(1);
bit Boolean Bit GetSqlBoolean Boolean GetBoolean
GetByte
is only used for tinyint
-columns.
Upvotes: 6