it does not gave any value
using (SqlCommand cmd = new SqlCommand("SELECT SUM(Paied) FROM Debt", new SqlConnection(Program.ConnectionString)))
{
cmd.Connection.Open();
SqlDataReader myReader = cmd.ExecuteReader();
while (myReader.Read())
{
TotalPaiedAll = Convert.ToDecimal( myReader["Paied"].ToString());
}
cmd.Connection.Close();
}
The reason you’re not getting a value is because
SUM(Paied)generates an anonymous column, not a column named Paied.Here is a simple fix for your problem:
And here is a better approach, using the ExecuteScalar method: