string sql2 = "SELECT SUM(fyringsolje) FROM Informasjon WHERE fyringsolje='Kull: 2,42 kg';";
SqlCommand myCommand2 = new SqlCommand(sql2, conn);
kullTotaltLabel.Text = "" + (int)myCommand2.ExecuteScalar();
I don't see the text of the label changing, i am afraid the query cannot be correct. I want to make sure the query is correct!
It cant be right. In the same select statement you are comparing the fyringsolje field to Text so that suggest that the value is a text field and you cant apply sum on it
I doubt that that you want the ; at the end of the query... but just not seeing the label changing suggests that if something's going wrong, you're swallowing any exception that's being thrown.
Before you fix the query, fix the design so that when errors occur, you get to find out about them - otherwise you'll never be confident about what's happened.
I'd also change the final line to:
kullTotaltLabel.Text = myCommand2.ExecuteScalar().ToString();
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