DataSet ds = new DataSet();
            DataTable codeTable = ds.Tables[0];
            if (codeTable.Rows.Count != 0)
            {
               //不为空就进来
            }codeTable != null 和 codeTable.Rows.Count 这两个方法是错误的,大家来研究一下吧

解决方案 »

  1.   

    dataset!=null&dataset.Tables.count>0&&ds.tables[0].rows.count>0
      

  2.   


    if (codeTable!=null && codeTable.Rows.Count != 0)
    {
        //不为空就进来
    }
      

  3.   

    设知道你ds.Tables[0]是什么啊,new DataTable,那么rows肯定是0
      

  4.   


    DataSet ds = new DataSet();
    if(ds!=null)
    {
       DataTable codeTable = ds.Tables[0];
       if (codeTable.Rows.Count != 0)
       {
          //不为空就进来
       }
    }
      

  5.   

    完整代码     public static DataTable QuerySqlDataTabe(string querySql) 
            {
                EIInfo outInfo = ExecQuery(querySql);
                DataSet ds = new DataSet();
                outInfo.GetBlockVal(ds);
                DataTable codeTable = ds.Tables[0];
                if (codeTable.Rows.Count != 0)
                {
                    DataRow newRow = codeTable.NewRow();
                    newRow[0] = "";
                    newRow[1] = "";
                    codeTable.Rows.InsertAt(newRow, 0);
                }
                return codeTable;
            }
      

  6.   

    ..用一个int类型的变量去接收也不行。。 比如  int a=codeTable.Rows.Count; 调试的时候把鼠标移到变量a上面竟然什么都不显示  说明codeTable.Rows.Count的值是
      

  7.   

    说白了 就是 codeTable.Rows.Count = codeTable.Rows.Count|0    大家明白我的意思了吧大神们
      

  8.   

                DataSet ds = new DataSet();
                DataTable codeTable = ds.Tables[0];
                if (codeTable.Rows.Count != 0)
                {
                   //不为空就进来
                }           只new了dataset 说好的datatable呢?ds.Tables[0]是啥??
      

  9.   

    一看就知道是错的你从哪里看出来有问题的,麻烦你指正一下。。
    ds.tables[0].rows.count>0 不成立... 因为 ds.tables[0].rows.count = ds.tables[0].rows.count|0   
      

  10.   

    完整代码     public static DataTable QuerySqlDataTabe(string querySql) 
            {
                EIInfo outInfo = ExecQuery(querySql);
                DataSet ds = new DataSet();
                outInfo.GetBlockVal(ds);
                DataTable codeTable = ds.Tables[0];
                if (codeTable.Rows.Count != 0)
                {
                    DataRow newRow = codeTable.NewRow();
                    newRow[0] = "";
                    newRow[1] = "";
                    codeTable.Rows.InsertAt(newRow, 0);
                }
                return codeTable;
            }
      

  11.   

    一看就知道是错的你从哪里看出来有问题的,麻烦你指正一下。。
    ds.tables[0].rows.count>0 不成立... 因为 ds.tables[0].rows.count = ds.tables[0].rows.count|0   你不是自己都判断了codeTable.Rows.Count != 0,难道他还会小于0?
    无非就是判断3点:
    dataset null
    dataset是否有datatable
    dataset里面的第一个表有没有数据。
      

  12.   


    俺写了个错误的东西出来,楼主请无视,,哈哈  知道我的意思了吧
    不是知道你意思,是你问题写的代码本来就不对,被带进“沟”里面了
    。本来就是错误的代码,希望你们能帮我解决这个问题上面有人说的很清楚了,new的dataset里面是null,没有tables[0]这个表,他肯定抛异常了。
      

  13.   

    一看就知道是错的你从哪里看出来有问题的,麻烦你指正一下。。
    ds.tables[0].rows.count>0 不成立... 因为 ds.tables[0].rows.count = ds.tables[0].rows.count|0   你不是自己都判断了codeTable.Rows.Count != 0,难道他还会小于0?
    无非就是判断3点:
    dataset null
    dataset是否有datatable
    dataset里面的第一个表有没有数据。
    说了啊,codeTable.Rows.Count不大于0,也不小于0,它的值是ds.tables[0].rows.count = ds.tables[0].rows.count|0   
      

  14.   


    俺写了个错误的东西出来,楼主请无视,,哈哈  知道我的意思了吧
    不是知道你意思,是你问题写的代码本来就不对,被带进“沟”里面了
    。本来就是错误的代码,希望你们能帮我解决这个问题上面有人说的很清楚了,new的dataset里面是null,没有tables[0]这个表,他肯定抛异常了。是的 我就是不知道怎么验证它不为null
      

  15.   


    俺写了个错误的东西出来,楼主请无视,,哈哈  知道我的意思了吧
    不是知道你意思,是你问题写的代码本来就不对,被带进“沟”里面了
    。本来就是错误的代码,希望你们能帮我解决这个问题上面有人说的很清楚了,new的dataset里面是null,没有tables[0]这个表,他肯定抛异常了。是的 我就是不知道怎么验证它不为null判断这3个条件:
    dataset为 null
    dataset是否有datatable
    dataset里面的第一个表有没有数据。
      

  16.   

    智商捉鸡啊。
    左侧的codeTable.Rows.Count代表的是Count对应的是codeTable.Rows.Count
    |是分割线
    右侧的是它的值0。你这个瞎扯淡什么啊
      

  17.   

    智商捉鸡啊。
    左侧的codeTable.Rows.Count代表的是Count对应的是codeTable.Rows.Count
    |是分割线
    右侧的是它的值0。你这个瞎扯淡什么啊我去....你试试就知道了唉。。count的值就是codeTable.Rows.Count|0 ,你怎么就看不懂呢
      

  18.   

    a不显示是因为你刚执行到它这段代码,a还没被赋值,你这段执行完毕后,你再看a就有值了
      

  19.   

    a不显示是因为你刚执行到它这段代码,a还没被赋值,你这段执行完毕后,你再看a就有值了
    试过了,,还是没有
      

  20.   


    if(dt!=null&&dt.Rows.Count>0)
    {
    //我都是先判断不为空为先
    }
      

  21.   


    dt.Rows.Count>0  这个判断无效。。 不信你试试
      

  22.   

    dt!=null 是可以 但是遇到我那样的方式用了 就行不通 了
      

  23.   


    public static DataTable QuerySqlDataTabe(string querySql) 
            {
                EIInfo outInfo = ExecQuery(querySql);
                DataSet ds = new DataSet();
                outInfo.GetBlockVal(ds);
                DataTable codeTable = ds.Tables[0];
                if (codeTable.Rows.Count != 0)
                {
                    DataRow newRow = codeTable.NewRow();
                    newRow[0] = "";
                    newRow[1] = "";
                    codeTable.Rows.InsertAt(newRow, 0);
                }
                return codeTable;
            }在吐槽一下,就算你的截图中codeTable.Rows.Count==0了,那他就直接return codeTable;有什么问题啊。
      

  24.   


    dataset != null && dataset.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0你把空格打出来啊  没空格就错了 
      

  25.   


    跟一下ds.Tables[0]的值,看看这个表有没有数据。
      

  26.   

    无非就是判断3点:
    dataset null
    dataset是否有datatable
    dataset里面的第一个表有没有数据。
    感觉23楼兄弟 说的没什么问题啊。
    这样判断 错在哪里?
      

  27.   

    看到这个,我笑喷了,并不是说把你赋值号右侧的东西给了左侧,|只是一个分隔符,提示的时候让你好理解,告诉你count为0,不要纠结了,就是这样的,你查询的没有数据,永远进不去“不为空就进来”
      

  28.   

    LZ是一个SB,老子写了这么多年的程序,一直都是用!=null && .count>0或.count!=0判断的。
      

  29.   

    智商捉鸡啊。
    左侧的codeTable.Rows.Count代表的是Count对应的是codeTable.Rows.Count
    |是分割线
    右侧的是它的值0。你这个瞎扯淡什么啊
    +1
    楼主一直在纠结codeTable.Rows.Count = codeTable.Rows.Count|0 。其实他连codeTable.Rows.Count|0的意思都没弄清楚。大家散了吧。
      

  30.   

    楼主你本身贴出的代码有问题,因为你还漏贴了对ds操作的语句,不然的话根本不会进入判断就报错的
                DataSet ds = new DataSet();
                DataTable codeTable = ds.Tables[0];//运行到这句就报错了的
                if (codeTable.Rows.Count != 0)
                {
                   //不为空就进来
                }
      

  31.   

    DataSet ds = new DataSet();执行DataTable codeTable = ds.Tables[0];后就提示
    "无法找到表 0。"如果单纯用1L的代码,建议LZ先调试了再说.  如果是用10L的代码,LZ还是看看ds.Tables里面到底是什么...ds.Tables是个List<DataTable>类型的东西.单纯New出来的DataSet的Tables必须是Count为0啊.像以下的代码:
     DataSet ds = new DataSet();
                DataTable table = new DataTable();
                ds.Tables.Add(table);
                DataTable codeTable = ds.Tables[0];
                if (codeTable.Rows.Count != 0)
                {
                    DataRow newRow = codeTable.NewRow();
                    newRow[0] = "";
                    newRow[1] = "";
                    codeTable.Rows.InsertAt(newRow, 0);
                }其中
    codeTable.Rows.Count是等于0的,因为table是new出来的,没有具体的row数据
    所以如前面几位大大所说,一是判断ds是否null,一是判断tables.Count是否为0或大于0,一是判断tables[0].Rows.Count是否为0或大于.至于说的codeTable.Rows.Count|0 , 那是为了便于清洗看到中间加了个分隔符,默认是白色的,或者你设置成为黑的了,或者截图出来是黑的.总之,大家的都有分隔符的.
      

  32.   

    Count的定义是int类型,怎么可能等于“ codeTable.Rows.Count|0”这样一个字符串???
    所以说,楼主,真不知道怎么说你好
      

  33.   

    正解 new就实例化一个了table了 table还能是null?
      

  34.   

    这问题也纠结半天?DataSet ds = new DataSet(); 
    if(DataSet.Tables.Count > 0)
    {
        DataTable codeTable = ds.Tables[0];
        if (codeTable.Rows.Count != 0)
        {
             //不为空就进来
        }
    }