c#从SQL数据库表中查询有几条记录并返回值,帮我看下哪里错了
publicintgetCapacity(){intcount=0;stringstate="0";stringsql=@"selectcount(*)fromsmall...
public int getCapacity()
{
int count = 0;
string state = "0";
string sql = @"select count(*) from small where state='" + state + "'";
sqlCon.Open();
SqlCommand sqlcmd = new SqlCommand(sql, sqlCon);
sdr = sqlcmd.ExecuteReader();
while (sdr.Read())
{
count = count + 1;
}
sqlCon.Close();
return count;
}
执行出来一直是1,我数据库里不止1条记录啊,while循环执行一次后就退出了 展开
{
int count = 0;
string state = "0";
string sql = @"select count(*) from small where state='" + state + "'";
sqlCon.Open();
SqlCommand sqlcmd = new SqlCommand(sql, sqlCon);
sdr = sqlcmd.ExecuteReader();
while (sdr.Read())
{
count = count + 1;
}
sqlCon.Close();
return count;
}
执行出来一直是1,我数据库里不止1条记录啊,while循环执行一次后就退出了 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询