数据视图过滤,对错误需要澄清
本文关键字:错误 视图 过滤 数据 | 更新日期: 2023-09-27 18:04:54
我已经创建了一个数据集,也采取了一个字符串变量isexmodule 这是在过滤期间使用的,我的代码如下
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' ) )"
给出一个异常'Invalid Column name [Y]'如果我从过滤器条件中删除'和' + isexmodule + ' = 'Y',那么它可以正常工作,为什么它考虑'Y'作为列
问题出在语句and "+IsExModul+" = 'Y' ) )
的最后一部分这应该是一些SQL文本,但isexmodule不是列名,其中值应该是'Y'
我已经将变量isexmodule从字符串更改为整数,现在它作为dataview中的过滤器工作良好
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'