DataView过滤,在Error上需要澄清

时间:2016-08-30 10:46:43

标签: c# asp.net

我创建了一个数据集,并且还采用了字符串变量IsExModul ,在过滤器中使用了我的代码如下

string IsExModul ="Y" ;//By some condition this variable is set to Y
 ReportDataView = new DataView(FullReportData, "ReportSection = '" + ReportSection + "' and ( IsPentesterAccess = 'Y' or (" + Convert.ToInt32(LoginUserInfo.Rows[0]["isadmin"]) + " = 1 and IsAdminAccess = 'Y') or (" + Convert.ToInt32(LoginUserInfo.Rows[0]["IsSevTempAcess"]) + " = 1 and IsSevTempAccess = 'Y') or ( " + Convert.ToInt32(LoginUserInfo.Rows[0]["IsWOModule"]) + " = 1 and IsWoModuleAccess = 'Y') or ( " + Convert.ToInt32(LoginUserInfo.Rows[0]["IsExModule"]) + " = 2 and IsExceptionAccess = 'Y') or ( " + Convert.ToInt32(LoginUserInfo.Rows[0]["IsExModule"]) + " IN (1,3)  and IsExceptionAccess = 'Y' and "+IsExModul+" = 'Y'  )   )"

它给出了一个例外'无效的列名[Y]' 如果我从过滤条件中删除'和'+ IsExModul +“='Y''然后它工作正常, 为什么将'Y'视为专栏。

2 个答案:

答案 0 :(得分:0)

问题出现在声明的最后部分and "+IsExModul+" = 'Y' ) ) 这应该是一些SQL文本,但是IsExModul不是列名,其值应为'Y'

答案 1 :(得分:0)

我已将变量IsExModul从字符串更改为整数,现在它在数据视图中作为过滤器工作正常

int IsExModul =1 ;//By some condition this variable is set to 1

ReportDataView = new DataView(FullReportData, "ReportSection = '" + ReportSection + "' and ( IsPentesterAccess = 'Y' or (" + Convert.ToInt32(LoginUserInfo.Rows[0]["isadmin"]) + " = 1 and IsAdminAccess = 'Y') or (" + Convert.ToInt32(LoginUserInfo.Rows[0]["IsSevTempAcess"]) + " = 1 and IsSevTempAccess = 'Y') or ( " + Convert.ToInt32(LoginUserInfo.Rows[0]["IsWOModule"]) + " = 1 and IsWoModuleAccess = 'Y') or ( " + Convert.ToInt32(LoginUserInfo.Rows[0]["IsExModule"]) + " = 2 and IsExceptionAccess = 'Y') or ( " + Convert.ToInt32(LoginUserInfo.Rows[0]["IsExModule"]) + " IN (1,3)  and IsExceptionAccess = 'Y' and " + IsExModul + " = 1   )   )", "SerialNumber", DataViewRowState.CurrentRows);  

但是我仍然不清楚为什么当它是字符串数据类型并且设置为' Y' ,有人可以帮助