I want to get the count of rows of a table.
cmd.CommandText = "SELECT COUNT(*) FROM (SELECT * FROM (SELECT * FROM EMPLOYEE ))";
Records = int.Parse(cmd.ExecuteScalar().ToString());
even if there is 1 row in employee table, Records always have value 0.
why ExecuteScalar() returns 0?
What you are trying to calculate is the number of rows in the EMPLOYEE table, therefore Pranav and Vinod are right. But assuming you try to simplify your situation just to point directly to your problem, I would say that you need to give names to your temporary tables like this:
That should do the trick.
One additional suggestion is not to use count(0); instead use count(0). ‘*’ brings all data in the view; which is an unnecessary performance decrement for count function.