sql count 结果怎么在C#中返回

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();

你可能感兴趣的:(数据库,职场,休闲)