Is there a way I can determine in .NET, for any arbitrary SQL Server result set, if a given column in the result can contain nulls?
For example, if I have the statements
Select NullableColumn From MyTable
and
Select IsNull(NullableColumn, '5') as NotNullColumn From MyTable
and I get a datareader like this:
var cmd = new SqlCommand(statement, connection);
var rdr = cmd.ExecuteReader();
can I have a function like this?
bool ColumnMayHaveNullData(SqlDataReader rdr, int ordinal)
{
//????
}
I want it to return true for the first statement, and false for the second statement.
rdr.GetSchemaTable() doesn't work for this because it returns whether the underlying column can be null, which is not what I want. There are functions on datareader that return the underlying sql type of the field, but none seem to tell me if it can be null..