asp.net想查询出SQL语句返回的行数,为什么获得值是负数
DBHelpdc=newDBHelp();stringstrCmd="selectcount(*)fromnewswhereLeibie='动态'";intdt=dc.E...
DBHelp dc = new DBHelp();
string strCmd = "select count(*) from news where Leibie='动态'";
int dt = dc.ExceRead(strCmd);
Label3.Text = dt.ToString();
能不能说详细点。具体HELP类怎么写 然后怎么调 //该方法返回一个SqlDataReader类型
public SqlDataReader ExceReads(string strComs)
{
sqlCmd = new SqlCommand(strComs, sqlCon);
SqlDataReader sdr = sqlCmd.ExecuteReader();
return sdr;
} 展开
string strCmd = "select count(*) from news where Leibie='动态'";
int dt = dc.ExceRead(strCmd);
Label3.Text = dt.ToString();
能不能说详细点。具体HELP类怎么写 然后怎么调 //该方法返回一个SqlDataReader类型
public SqlDataReader ExceReads(string strComs)
{
sqlCmd = new SqlCommand(strComs, sqlCon);
SqlDataReader sdr = sqlCmd.ExecuteReader();
return sdr;
} 展开
3个回答
展开全部
哎...方法名用错了
一看就是我以前经常犯的错误
检查DBHelper类写法
应该是这个方法
ExecuteScalar();
不是ExceRead();
SqlConnection conn = new SqlConnection();
conn.Open();
string strCmd = "select count(*) from news where Leibie='动态'";
SqlCommand com = new SqlCommand(strCmd, conn);
object obj = com.ExecuteScalar();
Label3.Text = obj.ToString();
一看就是我以前经常犯的错误
检查DBHelper类写法
应该是这个方法
ExecuteScalar();
不是ExceRead();
SqlConnection conn = new SqlConnection();
conn.Open();
string strCmd = "select count(*) from news where Leibie='动态'";
SqlCommand com = new SqlCommand(strCmd, conn);
object obj = com.ExecuteScalar();
Label3.Text = obj.ToString();
参考资料: 经验
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询