简单而又复杂,用最少的代码取得“select * from table”的行数,别用循环! select sum(*) from table 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 SqlCommand cmd = new SqlCommand("Select Count(*) from table","数据库连接");int count;try { count = (int)cmd.ExecuteScalar(); //一定要try,否则如果没有数据,这里转型会出错}catch { count = 0;} Sum是统计字段的值,Count才是统计记录的数量 string comstr="select count(*) from table where...";SqlCommand mycom=new SqlCommand(con,comstr);int count=(int)mycom.ExecuteScalar(); Select count(*) from table sqlcommand sqlcmd=new sqlcommand(sqlconn,"select * from table")int RowCount=sqlcmd.executereader() int RowCount=sqlcmd.executereader()这个可以么,我现在不能试 >>int RowCount=sqlcmd.executereader()>>这个可以么,我现在不能试可以,但最好用 ExecuteScalar() Select Count(*) from tableint RowCount=sqlcmd.ExecuteScalar(); 如果没有数据,应该会返回0,因为你用的是select count(*) from yourtable. dataset.table[0].rows.count 无法进行级联删除 vs2008的asp.net开发环境的安装 怎样对List<T>做检索 怎么设置repeater行的背景色 如何设置TableCell的样式 ASP.NET怎样取值 急求助,ASP.NET调试时提示web服务器运行不是ASP.NET1.1版 asp和asp.net中的cookie 关于DIV滚动条的问题 如何调用动态链接库 在Asp.net中,怎样传递参数到VB写的OCX组件里去? 能否用web 控件里面的 textbox控件绑定数据表里的数据
try {
count = (int)cmd.ExecuteScalar(); //一定要try,否则如果没有数据,这里转型会出错
}
catch {
count = 0;
}
SqlCommand mycom=new SqlCommand(con,comstr);
int count=(int)mycom.ExecuteScalar();
int RowCount=sqlcmd.executereader()
这个可以么,我现在不能试
>>这个可以么,我现在不能试可以,但最好用 ExecuteScalar()