sel="select A.usertype,B.username from A,B where A.ID=B.ID"A表中usertype字段有3种值分别为 新客户,老客户,免费客户
现在我想求出新客户,老客户,免费客户的数量分别是多少?应该怎么处理??
我使用SqlDataReader DR=exe.(sel);
While(DR.read())
{
DR["usertype"]
}
这种方法不对!!
应该怎么做???

解决方案 »

  1.   

    select count(username ) as c from A,B where A.ID = B.ID group usertype这样不行吗?
      

  2.   

    yiyioo(天一(日啃一文,月习一类,不求通透,只求半解))
    -------------------------------------------
    sel="select A.usertype,B.username from A,B where A.ID=B.ID"这条语句还要生成
    DataGrid的数据源!那种写法恐怕不行吧??
      

  3.   

    sel="select A.usertype,B.username,(Select Count(*) From B Where A.ID = B.ID) As CountSum from A,B where A.ID=B.ID"
      

  4.   

    string sql = "select count(username ) as c from A,B where A.ID = B.ID group usertype";
    DataSet ds = SqlHelper.ExecuteDataset("连接字符串", CommandType.Text, sql);
    return ds.Tables[0];注意:using Microsoft.ApplicationBlocks.Data;
    必须要有这个包才可以
      

  5.   

    如果只希望出最终人数结果用楼上的SQL语句即可如果希望列出用户并且给出统计就在绑定后期做,用DataGrid可以写到页脚去统计
      

  6.   

    sel="select A.usertype,max(B.username) as username, count(A.usertype) as 数量 from A,B where A.ID=B.ID group by A.usertype"
      

  7.   

    上面的那个不对,这个:
    sel="select A.usertype, count(A.usertype) as 数量 from A group by A.usertype"
      

  8.   

    sel="select A.usertype, count(A.usertype) as 数量 from A group by A.usertype
    我想知道,用什么方法能得到每一类的值?
    是用ExecuteScalar()吗????
      

  9.   

    我日
    sel="select A.usertype,B.username,(Select Count(*) From B Where A.ID = B.ID) As CountSum from A,B where A.ID=B.ID"我的不行???
      

  10.   

    sel="select A.usertype,B.username,(Select Count(*) From B Where A.ID = B.ID) As CountSum from A,B where A.ID=B.ID"
    用什么方法执行啊???
    ExecuteScalar()?
    SqlDataAdapter()???
      

  11.   

    谁能写一下如何才能得到每种类型个数的C#代码???
    不要只写sql语句!!谢谢!!!
      

  12.   

    int a1=0,a2=0,a3=0,a4=0,a5=0,a=0;
    try{
       while(DR.Read())
       {
       if(DR["客户类别"].ToString().Trim()=="新客户")
       {
       a1++;
       }
       if(DR["客户类别"].ToString().Trim()=="老客户")
       {
       a2++;
       }
       if(DR["客户类别"].ToString().Trim()=="潜在")
       {
       a3++;
       }
       if(DR["客户类别"].ToString().Trim()=="免费")
       {
       a4++;
       }
       if(DR["客户类别"].ToString().Trim()=="掉线")
       {
       a5++;
       }
       a++;
       }
    }
    catch(Exception ex)
    {
    this.Label13.Text=ex.ToString();
    }
      

  13.   

    dim conn as New Sqlconnection("....")
    conn.open()
    dim strCmd as string
    strCmd = "Select ...."
    dim cmd as new sqlcommand(strcmd,conn)
    Dim dr As SqlDataReader
    dr = cmd1.ExecuteReader()
    while dr.read()
        Select Case dr.Items(0)
            Case   "新客户"
               a1 = a1+1
            Case   "老客户"
               a2 = a2+1
            ....
        End Select
    Loopdr.close
    cmd.close
    conn.close
      

  14.   

    select a.usertype , count(a.usertype) CustomerNum from (
    select A.usertype,B.username from A,B where A.ID=B.ID ) a group by a.usertype
    替换你的 SQL 语句,Try.....