DataSet ds = new DataSet();
DataTable codeTable = ds.Tables[0];
if (codeTable.Rows.Count != 0)
{
//不为空就进来
}codeTable != null 和 codeTable.Rows.Count 这两个方法是错误的,大家来研究一下吧
DataTable codeTable = ds.Tables[0];
if (codeTable.Rows.Count != 0)
{
//不为空就进来
}codeTable != null 和 codeTable.Rows.Count 这两个方法是错误的,大家来研究一下吧
if (codeTable!=null && codeTable.Rows.Count != 0)
{
//不为空就进来
}
DataSet ds = new DataSet();
if(ds!=null)
{
DataTable codeTable = ds.Tables[0];
if (codeTable.Rows.Count != 0)
{
//不为空就进来
}
}
{
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;
}
DataTable codeTable = ds.Tables[0];
if (codeTable.Rows.Count != 0)
{
//不为空就进来
} 只new了dataset 说好的datatable呢?ds.Tables[0]是啥??
ds.tables[0].rows.count>0 不成立... 因为 ds.tables[0].rows.count = ds.tables[0].rows.count|0
{
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;
}
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里面的第一个表有没有数据。
俺写了个错误的东西出来,楼主请无视,,哈哈 知道我的意思了吧
不是知道你意思,是你问题写的代码本来就不对,被带进“沟”里面了
。本来就是错误的代码,希望你们能帮我解决这个问题上面有人说的很清楚了,new的dataset里面是null,没有tables[0]这个表,他肯定抛异常了。
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
俺写了个错误的东西出来,楼主请无视,,哈哈 知道我的意思了吧
不是知道你意思,是你问题写的代码本来就不对,被带进“沟”里面了
。本来就是错误的代码,希望你们能帮我解决这个问题上面有人说的很清楚了,new的dataset里面是null,没有tables[0]这个表,他肯定抛异常了。是的 我就是不知道怎么验证它不为null
俺写了个错误的东西出来,楼主请无视,,哈哈 知道我的意思了吧
不是知道你意思,是你问题写的代码本来就不对,被带进“沟”里面了
。本来就是错误的代码,希望你们能帮我解决这个问题上面有人说的很清楚了,new的dataset里面是null,没有tables[0]这个表,他肯定抛异常了。是的 我就是不知道怎么验证它不为null判断这3个条件:
dataset为 null
dataset是否有datatable
dataset里面的第一个表有没有数据。
左侧的codeTable.Rows.Count代表的是Count对应的是codeTable.Rows.Count
|是分割线
右侧的是它的值0。你这个瞎扯淡什么啊
左侧的codeTable.Rows.Count代表的是Count对应的是codeTable.Rows.Count
|是分割线
右侧的是它的值0。你这个瞎扯淡什么啊我去....你试试就知道了唉。。count的值就是codeTable.Rows.Count|0 ,你怎么就看不懂呢
试过了,,还是没有
if(dt!=null&&dt.Rows.Count>0)
{
//我都是先判断不为空为先
}
dt.Rows.Count>0 这个判断无效。。 不信你试试
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;有什么问题啊。
dataset != null && dataset.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0你把空格打出来啊 没空格就错了
跟一下ds.Tables[0]的值,看看这个表有没有数据。
dataset null
dataset是否有datatable
dataset里面的第一个表有没有数据。
感觉23楼兄弟 说的没什么问题啊。
这样判断 错在哪里?
左侧的codeTable.Rows.Count代表的是Count对应的是codeTable.Rows.Count
|是分割线
右侧的是它的值0。你这个瞎扯淡什么啊
+1
楼主一直在纠结codeTable.Rows.Count = codeTable.Rows.Count|0 。其实他连codeTable.Rows.Count|0的意思都没弄清楚。大家散了吧。
DataSet ds = new DataSet();
DataTable codeTable = ds.Tables[0];//运行到这句就报错了的
if (codeTable.Rows.Count != 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 , 那是为了便于清洗看到中间加了个分隔符,默认是白色的,或者你设置成为黑的了,或者截图出来是黑的.总之,大家的都有分隔符的.
所以说,楼主,真不知道怎么说你好
if(DataSet.Tables.Count > 0)
{
DataTable codeTable = ds.Tables[0];
if (codeTable.Rows.Count != 0)
{
//不为空就进来
}
}