1

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?

4

2 回答 2

6

利用

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

或者,如果您要迭代许多行,请保留序数并重新使用它:

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

while (reader.Read())
{
    reader.IsDBNull(poNumberOrdinal);
}
于 2014-03-17T13:31:21.603 回答
1

尝试这个:

currentOrder.PONumber = reader["PONumber"].Equals(DBNull.Value) ? 
                         "Geen klantreferentie" :  reader.GetString("PONumber"));
于 2014-03-17T13:32:52.767 回答