问题描述
selectcount(*)ffrom[Book]groupbyType怎样执行并捕获这跳语句的返回值我需要显示type和count帮帮忙,谢谢!
解决方案
解决方案二:
selecttype,count(*)asffrom[Book]groupbyType显示的话方法很多啊。用dataset就可以了
解决方案三:
怎么还没解决?
解决方案四:
datatable
解决方案五:
引用楼主wpx933的帖子:
selectcount(*)ffrom[Book]groupbyType怎样执行并捕获这跳语句的返回值我需要显示type和count帮帮忙,谢谢!
用个dataset来接受这条语句的返回值,读dataset就可以读出来count了。SqlConnectionconn=newSqlConnection(“server=(local);uid=sa;pwd=;database=yourdatabase”);conn.Open();SqlDataAdaptersd=newSqlDataAdater(“selectcount(*)ffrom[Book]groupbyType”,conn)DataSetds=newDataSet();sd.fill(ds);conn.close();intcount=(int)ds.Tables[0].rows[0][0].ToString();
解决方案六:
publicstaticSqlDataReaderExecuteReader(stringconnectionString,CommandTypecmdType,stringcmdText,paramsSqlParameter[]commandParameters){SqlCommandcmd=newSqlCommand();SqlConnectionconn=newSqlConnection(connectionString);//weuseatry/catchherebecauseifthemethodthrowsanexceptionwewantto//closetheconnectionthrowcode,becausenodatareaderwillexist,hencethe//commandBehaviour.CloseConnectionwillnotworktry{PrepareCommand(cmd,conn,null,cmdType,cmdText,commandParameters);SqlDataReaderrdr=cmd.ExecuteReader(CommandBehavior.CloseConnection);cmd.Parameters.Clear();returnrdr;}catch{conn.Close();throw;}}