SqlDataReader.GetOrdinal is your answer
if (!dr.IsDBNull(dr.GetOrdinal("ProductState")))
You could write an extension method to encapsulate this functionality
public static class ReaderExtensions
{
public static bool IsDBNull(this SqlDataReader reader, string colName)
{
return reader.IsDBNull(reader.GetOrdinal(colName));
}
}
And now you will be able to call the IsDBNull passing a string
if (!dr.IsDBNull("ProductState"))
Looking at your code (reader.GetString("ProductState"))
I thought that you are using the MySql provider that supplies an extension GetString
(and other GetXXXX) that takes a column name as parameter. But if you have an SqlDataReader then you need to change also that call using the GetOrdinal (or another extensions) because the SqlClient doesn't have a GetString with a column name as parameter