Home > Mobile >  Finding sum of values in a column
Finding sum of values in a column

Time:12-30

I am trying to find sum of values in a column using a condition but the result am getting is null am not sure of where the problem is coz i have tried running the sql database access but and it works but when i it at in the progam it does not work

So i need assistance on this one

The code is below

Blockquote

  p.Query="SELECT SUM(income) FROM Emp_income  WHERE username ='"   frmlogin.username   "'"; 
            using (IDbCommand command = new OleDbCommand(p.Query, p.Con))

            {
                object answer=command.ExecuteScalar();
                lblincome.Text=Convert.ToString(answer);
            }

CodePudding user response:

Add try/catch block to ExcuteScalar() for error message, for connection oriented ADO.Net you have to Open connection before executing the command like con.Open()

  • Related