strint str ="select tmp1,tmp2,tmp3 from db"
      。
                DataSet ds = new DataSet();
                mda.Fill(ds, "db");
用ds.Tables[0].Rows.Count能得到sql返回的行数
怎么能想到sql查询返回有值的列数?(只统计有值的列数)

解决方案 »

  1.   

    DataRow[] rows = ds.Tables["db"].Select("tmp1<>'' and tmp2<>'' and tmp3<>''","");
      

  2.   

    foreach(datacolumn dc in ds.table[0].columns)
    {
       foreach(datarow dr in ds.table[0].rows)
       {
         if(有值)
          {
            count+=1;
            break;//跳出本次循环
           }
       }
    }试试
      

  3.   

    select tmp1,tmp2,tmp3 from db 
    where tmp1 is not null
     and tmp2 is not null
     and tmp3 is not null
      

  4.   

    ds.Tables[0].Columns.Count
    就是列数
      

  5.   

    strint str ="select tmp1,tmp2,tmp3 from db"
              。
                    DataSet ds = new DataSet();
                    mda.Fill(ds, "db");-----------------------------
    tmp1,tmp2,tmp3
    你这里自己定义了三个列 啊!
    怎么能控制列的显示啦??
    好像不能把1!
    呵呵
      

  6.   

    select 有值的行数=count(*)  from db
    where tmp1 is not null and tmp2 is not null and tmp3 is not nullselect 有值的列数=
           case when (select  count(*)  from db where tmp1 is null )>0 then 0 else 1 end
           +
           case when (select  count(*)  from db where tmp2 is null )>0 then 0 else 1 end
           +
           case when (select  count(*)  from db where tmp3 is null )>0 then 0 else 1 end
      

  7.   

    ds.Tables[0].Columns .Count
    不就是列数了吗
      

  8.   

    列数?不太明白
    比如
    tmp1,tmp2,tmp3 
    1   ,   1,  1
        ,   1,  1
        ,   1,  
    1   ,    ,是想得到
    第1行:3列
    第2行:3列
    第3行:1列
    第4行:1列如果是的话,统计一下就可以了foreach (DataRow dr in ds.Tables[0].Rows)
    {
        int count = 0;
        foreach (DataColumn dc in ds.Tables[0].Columns)
        {
            if (dr[dc].ToString() != string.Empty)
            {
                count++;
            }
        }
         ////count
    }
      

  9.   


    1 DataSet.Table[0].Rows[ i ][ j ]        其中i 代表第 i 行数, j 代表第 j 列数  2 DataSet.Table[0].Rows[ i ].ItemArray[ j ]        其中i 代表第 i 行数, j 代表第 j 列数  3 DataSet.Tables[0].Columns.Count        取得表的总列数 4 DataSet.Tables[0].Rows.Count       取得表的总行数  5 DataSet.Tables[0].Columns[ i ].ToString()       取得表的 i 列名
      

  10.   

    ds.Tables[0].Columns.Count 你就读取出3列来了
      

  11.   

    呵呵 ds.Tables[0].Columns.count