第1个回答 2007-04-13
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();本回答被提问者采纳
第2个回答 2007-04-05
SqlConnection conn = new SqlConnection ("server=.;DataBase=数据库名;UID=用户名;pwd=密码;");
SqlCommand cmd = new SqlCommand ("select count(no) from 表名",conn);
cmd.Open();
object obj = null;
obj = cmd.ExecuteScalar();
num = (int)obj;
cmd.Close();
这是无参的!
第3个回答 2007-04-04
在sql里写一个函数,直接返回count值就可以了