Question

I try to use

currentOrder.PONumber = (reader.IsDBNull("PONumber") ? "Geen klantreferentie" : reader.GetString("PONumber"));

and I have the following errors:

The best overloaded method match for 'System.Data.Common.DbDataReader.IsDBNull(int)' has some invalid arguments.

and

Argument 1: cannot convert from 'string' to 'int'.

When I use the columnindex in IsDBNull, I have the following error:

Data is Null. This method or property cannot be called on Null values.

How can I solve this?

Was it helpful?

Solution

Use

reader.IsDBNull(reader.GetOrdinal("PONumber")) 

Or if you are iterating many rows, keep hold of the ordinal and re-use it:

var poNumberOrdinal = reader.GetOrdinal("PONumber");

while (reader.Read())
{
    reader.IsDBNull(poNumberOrdinal);
}

OTHER TIPS

Try This:

currentOrder.PONumber = reader["PONumber"].Equals(DBNull.Value) ? 
                         "Geen klantreferentie" :  reader.GetString("PONumber"));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top