如何设置正确的数据集参数.表[0].计算(字符串表达式,字符串筛选器)



我无法从以下代码块中获得正确的结果:

object ob = ds_bug.Tables[0].Compute("Count(id)",str_vertical +"= '"+"' and "+str_horizontal+" = '"+first_row.Cells[j].Text.ToString()+"'");// ds_bug has been filled some data.

str_vertical和str_horizontal是ds_bug.Tables[0]中的两个字段,当我调试代码时,我可以看到它们的值也是正确的。

我用类似"a='###'和b='###'"的字符串设置筛选器有问题吗?

首先,您应该拆分方法调用以及表达式和筛选器的初始化,这样会更清楚:

我假设first_row.Cells[j].Text.ToString()是您之前查询过的一个静态值,所以您可以将其声明为:

String firstRowCellsJText = first_row.Cells[j].Text.ToString();
String expression="Count(id)";
String filter = "str_vertical=str_horizontal + " + firstRowCellsJText;
object ob = s_bug.Tables[0].Compute(expression,filter);

最新更新