'System.Data.Common.DbDataReader.IsDBNull(int)' 有一些无效参数

'System.Data.Common.DbDataReader.IsDBNull(int)' has some invalid arguments

我正在尝试处理来自数据库列(具有 intnull)的空值

我写了这段代码:

int? nullInt = null; 
int? typeTwo = myReader.IsDBNull(myReader["Type2"]) ? nullInt : (int)myReader["Type2"];

但是我得到这个错误:

The best overloaded method match for 'System.Data.Common.DbDataReader.IsDBNull(int)' has some invalid arguments Can you tell me how to fix this? Thanks.

看起来 IsDBNull 接受 ìnt 作为参数。您可以使用 GetOrdinal method like;

获取 Type2 列的编号
myReader.IsDBNull(myReader.GetOrdinal("Type2"))