抱歉,刚才写错了 select Count(case syclass when "111" then syclass end ) ,Count(case syclass when "222" then syclass end ),Count(case syclass when "333" then syclass end ) from SYTB
if(rowIndex["sy"].ToString()="111")=====>if(rowIndex["sy"].ToString().Trim()=="111")把=换成 ==,不知道你编译怎么通过的,另外用循环来做这种事情不好,太慢,可以考虑用 DataView dv = new DataView(myDs.Tables["sy"],"sy='111'","", DataViewRowState.CurrentRows)if (dv.Count>0) int counter = dv.Count另外你这三个字段是什么类型的需要搞清楚
SqlConnection sqlConn1=new SqlConnection("data source=localhost;persist security info=False;initial catalog=KYGLdatabase ");SqlCommand myCommand = new SqlCommand("select distinct syclass,count(*) As ComputerColumn from SYTB group by syclass",sqlConn1);sqlConn1.Open(); SqlDataReader dr = myCommand.ExecuteReader(); string strnum=null; do { strnum+=Convert.ToString(dr.GetInt32(1))+","} while (myReader.NextResult());strnum = strnum.SubString(0,strnum.Length -1); dr.Close(); sqlConn1.Close();
SqlConnection sqlConn1=new SqlConnection("data source=localhost;persist security info=False;initial catalog=KYGLdatabase ");SqlCommand myCommand = new SqlCommand("select distinct syclass,count(*) As ComputerColumn from SYTB group by syclass",sqlConn1);sqlConn1.Open(); SqlDataReader dr = myCommand.ExecuteReader(); string strnum=null; do { strnum+=Convert.ToString(dr.GetInt32(1))+","} while (dr.NextResult());strnum = strnum.SubString(0,strnum.Length -1); dr.Close(); sqlConn1.Close();
select count(case syclass when "111"),count(case syclass when "222"),count(case syclass when "333") from SYTB
string connstr="workstation id=IMAGE;packet size=4096;Trusted_Connection=Yes;data source=localhost;persist security info=False;initial catalog=KYGLdatabase ";
SqlConnection sqlConn1=new SqlConnection( connstr); string mySelectQuery="SELECT * FROM sytb"; SqlCommand myCommand = new SqlCommand(mySelectQuery,sqlConn1);
sqlConn1.Open(); SqlDataAdapter Adapter = new SqlDataAdapter();
Adapter.SelectCommand= myCommand;
DataSet myDs = new DataSet();
Adapter.Fill(myDs,"sy");
SqlCommandBuilder MyCommandBuild=new SqlCommandBuilder (Adapter); foreach(DataRow rowIndex in myDs.Tables["sy"].Rows)
{
if(rowIndex["sy"].ToString()="111")
num1=num1+1;
else
num2=num2+1;
}这样为什么得不到num1,num2的值呢?if(rowIndex["sy"].ToString()="111")这句错在哪
select
Count(case syclass when "111" then syclass end ) ,Count(case syclass when "222" then syclass end ),Count(case syclass when "333" then syclass end )
from SYTB
DataView dv = new DataView(myDs.Tables["sy"],"sy='111'","", DataViewRowState.CurrentRows)if (dv.Count>0)
int counter = dv.Count另外你这三个字段是什么类型的需要搞清楚
就是想要查询的记录数啊怎样查询所得的结果赋给统计图表参数num1,num2,num3
?
{
if(rowIndex["syclass"].ToString() == "111")
num1 += 1;
elseif(rowIndex["syclass"].ToString() == "222")
num2 += 1;
else
num3 += 1;
}
try
select distinct syclass,count(*) from SYTB group by syclasslike:
SELECT DISTINCT CategoryID, COUNT(*) AS Expr1
FROM Products
GROUP BY CategoryIDresult:CategoryID Expr1
1 12
2 12
3 13
4 10
5 7
6 6
7 5
8 12
string TableHeight = "110"; //整体高度
string fontsize = "2"; //字体大小
string fontcolor = "#999999"; //字体颜色
string strnum = "num1,num2"; //统计对象数据 数据间以“,”分隔
string strmemo = "重点项目,面上项目"; //统计对象说明 说明间已“,”分隔 MainPic ShowPic = new MainPic();
ShowPic.GetImageHTML(TableWidth,TableHeight,fontsize,fontcolor,strnum,strmemo); mainpic是已经封装的一个通用类这样赋值是错的,请问错在哪,接我前面的代码的
得到的是一些二进制数吗?因为我将其显示出来是,全是111,111111而且划成10进制结果好象也不对啊
string connstr="workstation id=IMAGE;packet size=4096;Trusted_Connection=Yes;data source=localhost;persist security info=False;initial catalog=KYGLdatabase ";
SqlConnection sqlConn1=new SqlConnection( connstr); string mySelectQuery="SELECT * FROM sytb"; SqlCommand myCommand = new SqlCommand(mySelectQuery,sqlConn1);
sqlConn1.Open(); SqlDataAdapter Adapter = new SqlDataAdapter();
Adapter.SelectCommand= myCommand;
DataSet myDs = new DataSet();
Adapter.Fill(myDs,"sy");
SqlCommandBuilder MyCommandBuild=new SqlCommandBuilder (Adapter); foreach(DataRow rowIndex in myDs.Tables["sy"].Rows)
{
if(rowIndex["sy"].ToString()="111")
num1=num1+1;
else
num2=num2+1;
}
SqlDataReader dr = myCommand.ExecuteReader();
string strnum=null;
do
{
strnum+=Convert.ToString(dr.GetInt32(1))+","} while (myReader.NextResult());strnum = strnum.SubString(0,strnum.Length -1);
dr.Close();
sqlConn1.Close();
SqlDataReader dr = myCommand.ExecuteReader();
string strnum=null;
do
{
strnum+=Convert.ToString(dr.GetInt32(1))+","} while (dr.NextResult());strnum = strnum.SubString(0,strnum.Length -1);
dr.Close();
sqlConn1.Close();
using System.Text;真的比较菜啊!开玩笑了
===》
strnum = strnum.Substring(0,strnum.Length -1);