I'm new to Microsoft SQL Server and I have a few lines of code like this:
private void readItem()
{
SqlDataReader reader = command.ExecuteReader();
if (reader.Read())
{
btn.ItemID = reader.GetInt32(0);
btn.ItemName = reader.GetString(1);
btn.ItemPrice = reader.GetInt32(2);
btn.ItemDiscount = reader.GetFloat(3); // Throw exception
itemPanel.Children.Add(btn);
}
}
I get this error:
System.InvalidCastException: 'Specified cast is not valid.'
I sure that both ItemDiscount
and reader.GetFloat(3)
are float
, but the exception still happens. I couldn't figure what is wrong here.
Please help me with this problem. Thanks all
Database : https://i.stack.imgur.com/tcsmf.jpg