SqlCommand mycom = new SqlCommand("select count(*) as id from Table1", mycon);
mycon.Open();
mycom.ExecuteNonQuery();
mycon.Close();我该怎样获得 id的值呢?如果我SqlCommand mycom = new SqlCommand("select count(*) as id from Table1", mycon);
mycon.Open();
int n = mycom.ExecuteNonQuery();
mycon.Close();
n的值是不是所有的行数呢》?我试了下不行。。如果用第一种情况该如何写 啊??
mycon.Open();
mycom.ExecuteNonQuery();
mycon.Close();我该怎样获得 id的值呢?如果我SqlCommand mycom = new SqlCommand("select count(*) as id from Table1", mycon);
mycon.Open();
int n = mycom.ExecuteNonQuery();
mycon.Close();
n的值是不是所有的行数呢》?我试了下不行。。如果用第一种情况该如何写 啊??
public static string CountA()
{
SqlConnection con=new SqlConnection("server=.;database=数据库名;uid=sa");
con.Open();
string strcmd="select count(*)from 表名 where ACardID is not null;
SqlCommand command=newSqlCommand(strcmd,con);
string A=command.Scalar().ToString();
con.Close();
return A;
}
ExecuteNonQuery()当然就是1。
要想得到count(*)的结果ExecuteScalar(),返回第一行第一列的值。