无法强制转换System类型的对象.Int64以键入System.Int32



我在上获得Unable to cast object of type 'System.Int64' to type 'System.Int32'

item.ItemCount = reader.GetInt32(reader.GetOrdinal("amount"));

我试过了:

item.ItemCount = reader.GetInt64(reader.GetOrdinal("amount"));

但我得到了:

Error   CS0266  
Cannot implicitly convert type 'long' to 'int'. 
An explicit conversion exists (are you missing a cast?)

字段是bigint,这是我第一次使用。网

您必须使用GetInt64

item.ItemCount = reader.GetInt64(reader.GetOrdinal("amount"));

SQLbigint等效于。NETlongGetInt64返回long,而GetInt32返回int

有关更多详细信息,请参阅本文档。

相关内容

最新更新