As I can see in your code block,
dr is SqlDataReader object. Where as
cmd.ExecuteScalar()[
^] returns the first column of the first row in the result set returned by the query. Additional columns or rows are ignored.
Additionally, I can see one more problem in your code is, your SQL query is wrong. I am modifying the query here. You can check it once.
Try this:
public int membercount(string tbl, string condition)
{
string query = "SELECT COUNT(*) FROM " + tbl;
if (condition.Trim().Length > 0)
{
query = query + " where " + condition;
}
cmd = new SqlCommand(query, con);
int a = Convert.ToInt32(cmd.ExecuteScalar());
return a;
}
--Amit