一个简单的问题, 但是转不过弯来,请大家帮忙解决一下,谢谢
先解释一下要执行的操作:我有一张表question ,我想要select里面总共记录了多少数据,我自己的代码如下,但是返回值是1,当然question表里不止一条数据。应该如何改代码,使其能够正确返回记录数。下面是我的代码:
public static int CountQuestion()
{
int sum;
string connStr = "server=(local);Initial Catalog=Test;Integrated Security=SSPI";
SqlConnection Conn = new SqlConnection();
Conn.ConnectionString = connStr;
string strSql = "select count(*) from question";
Conn.Open();
SqlDataAdapter cmd = new SqlDataAdapter(strSql,Conn);
DataSet dsCount = new DataSet();
cmd.Fill(dsCount);
sum = dsCount.Tables[0].Rows.Count;
Conn.Close();
return sum;
}