I get Unable to cast object of type 'System.Int64' to type 'System.Int32' on:
item.ItemCount = reader.GetInt32(reader.GetOrdinal("amount"));
I tried:
item.ItemCount = reader.GetInt64(reader.GetOrdinal("amount"));
But I got:
Error CS0266
Cannot implicitly convert type 'long' to 'int'.
An explicit conversion exists (are you missing a cast?)
The field is bigint and this is my first experience with .Net.
You have to use GetInt64
item.ItemCount = reader.GetInt64(reader.GetOrdinal("amount"));
SQL bigint is the equivalent to .NET long, GetInt64 returns a long, while GetInt32 returns an int.
See this documentation for more detail.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With