Columns of a table in db can store a null values (as DBNulls). Is there a way I can get this info from IDataReader or DbDataReader?
using (var reader = command.ExecuteReader())
{
//can I get the column info like if it supports null value if I pass the ordinal?
reader.CheckIfSupportsNull(someIndex) ???
while (reader.Read())
{
}
}
I do know I can read the cell values and check it against DBNull.Value, but I'm not asking if I can check the read value is null, but if I can check if the column itself supports DBNulls irrespective of the actual values present in table.
I would like to know if this is possible with MySqlDataReader and/or SqlDataReader..
@usr's answer pointed me in right direction. I got it done like this:
should work.
Note: As @Edper mentions
does the job too. This has an added advantage that you dont have to reference
System.Data.DataSetExtensions.dllwhich is required forField<T>extension method.