Wednesday, October 29, 2008

Count Number of record in Table

Try this

public int Count_Company()
{
SqlConnection conn = new SqlConnection(ConnectionString);
SqlCommand comm = new SqlCommand();
comm.CommandText = "Select count(UserName) from CompanyData"; comm.CommandType = CommandType.Text;
comm.Connection = conn;
conn.Open();
rows = int.Parse(comm.ExecuteScalar().ToString());
conn.Close();
return rows;
}

Good Luck

No comments: