using System.Data.SqlClient;
 
SqlConnection conn =new SqlConnection(
"server=localhost; Initial Catalog=数据库的名字;Integrated Security=SSPI");
 
SqlCommand countCmd = conn.CreateCommand();
countCmd.CommandText="select count(no) as noCount from ";
 
conn.Open();
 
int num = (int)countCmd.ExecuteScalar();
countCmd.Dispose();
conn.Close();