对不起,打错了
ds.Tables[0].Rows.Count

解决方案 »

  1.   

    ds.Tables.Count
    ds.Tables[0].Rows.Count最好两个都使用
      

  2.   

    ds.tables.count判断有几个表
    ds.tables[i].rows.count判断某个表是否有数据
      

  3.   

    if(ds!=null && ds.Tables.Count>0 && ds.Tables[0].Rows.Count>0)
    {
    }
      

  4.   

    必须要对dataset里的每个dataTable 进行判断:
    bool flag=true;  //用来判断DataTable中有无数据的标志。如果某个表中有数据,则flag=false。
    for each (DataTable dt in ds)
    {
       if(dt.Rows.Count>0)
       {
           flag=false;
           exit for;
       }
    }
    if(!flag)
    {
        //有数据。
    }
    else
    {
        //无数据。
    }
      

  5.   

    按你的想法,只能如下了:
    if(ds!=null && ds.Tables.Count>0 )
    {
        for (int i=0; i<ds.Tables.Count;i++)
        {
            if (ds.Tables[i].Rows.Count>0)
            {
                System.Console.Write("有数据!")
                break;
            }
        }
    }
    (也把数据给取出来了)
    int tmpInt=0;
    string tmpString=null;
    object tmpObj=null;if(ds!=null && ds.Tables.Count>0 )
    {
        for (int i=0; i<ds.Tables.Count;i++)
        {
            if (ds.Tables[i].Rows.Count>0)
            {
                for (int l=0; l<ds.Tables[i].Rows.Count)
                {
                    for (int j=0; j<ds.Tables[i].Columns.Count)
                    {
                        if (ds.Tables[i].Rows[l][j] is int)
                        {
                            tmpInt=(int)ds.Tables[i].Rows[l][j];
                        }
                        else if (ds.Tables[i].Rows[l][j] is string)
                        {
                            tmpString=(string)ds.Tables[i].Rows[l][j];
                        }
                        else
                        {
                            tmpObj=ds.Tables[i].Rows[l][j];
                        }
                    }
                }
            }
        }
    }