映射器类中的参数超出范围异常

本文关键字:范围 异常 参数 映射 | 更新日期: 2023-09-27 18:35:28

我正在使用MVP模式编程。在任务类中,我正在调用该函数。

   private List<ValuePair > DisplayUserRole(string sName)
            {
                MySqlConnection connection = DbAccess.OpenConnection(ConnectionStringName.LabTrack);
                _mapper1 = new UserAuthorizationMapper(connection);
                int ixCustomer=1;
                int ixProgram=1;
                int ixWorkPackage=1;
                int ixActivity=1;
                string ixUsercode="626e28e8-e67a-4d11-8d2c-129d0ab79e96";
                bool isUserAuthorized = _mapper1.IsUserAuthorised(sName, ixCustomer, ixProgram, ixWorkPackage, ixActivity, ixUsercode);
                List<ValuePair> listUserRoleValuePair = new List<ValuePair>();
                var ixUserList= _mapper1.FindUserRoleLike(sName,ixCustomer,ixProgram,ixWorkPackage,ixActivity);
                User user = null;
                foreach (var ixUser in ixUserList)
                {
                    user = new UserMapper(connection).FindById(ixUser);
                    if (user != null)
                    {
                        var name = user.SFirstName + " " + user.SLastName;
                        listUserRoleValuePair.Add(new ValuePair(ixUser, name));
                    }
                }
                return listUserRoleValuePair;    
}     

在映射器类中,我在选择查询中得到了 ArgumentoutofRangeException,说"索引和长度必须引用字符串中的位置"。

public bool IsUserAuthorised(string userRole, int ixCustomer, int ixProgram, int ixWorkPackage, int ixActivity, string ixUser)
            {
                bool result = false;
                SelectAll(Cmd(@"SELECT CASE WHEN Count(*)>=1 THEN 'True' "+
                            " ELSE 'False' END AS IsUserAuthorised " + 
                            " FROM (SELECT  ua.ixUserAuthorization FROM tblechecklistuserroleassignmentxref ra "+ 
                            " INNER JOIN tblechecklistuserrole ur ON ur.ixUserRole=ra.ixUserRole AND ur.sname='?0' "+ 
                            " INNER JOIN tblechecklistuserauthorization ua ON au.ixUserAuthorization=ra.ixUserAuthorization "+ 
                            " AND ua.ixcustomer='?1'AND ua.ixprogram='?2'AND ua.ixworkpackage='?3'AND ua.ixactivity='?4' "+ 
                            " AND ua.ixUser='?5') a ",
                            userRole,
                            ixCustomer,
                            ixProgram,
                            ixWorkPackage,
                            ixActivity,
                            ixUser ),                                                                              
                            delegate(MySqlDataReader reader)
                            {
 result=Convert.ToBoolean(GetDbValue<string>(reader,"isUserAuthorised"));
                                                       });
                 return result;
            }

如何修改我的查询以获取要执行的代码。

映射器类中的参数超出范围异常

不是

result=Convert.ToBoolean(GetDbValue<string>(reader,"isUserAuthorised"));

需要

result=Convert.ToBoolean(GetDbValue<string>(reader,"IsUserAuthorised")); (capitalised)

我猜你的错误与结果搜索有关,而不是查询......

问号后没有单引号。

public bool IsUserAuthorised(string userRole, int ixCustomer, int ixProgram, int ixWorkPackage, int ixActivity, string ixUser)         
    {              
   bool result = false;     
   SelectAll(Cmd(@"SELECT CASE WHEN Count(*)>=1 THEN 'True'  ELSE 'False' END AS IsUserAuthorised " +                             
 " FROM (SELECT  ua.ixUserAuthorization FROM tblechecklistuserroleassignmentxref ra "+                           
   " INNER JOIN tblechecklistuserrole ur ON ur.ixUserRole=ra.ixUserRole AND ur.sname=?0 "+                          
    " INNER JOIN tblechecklistuserauthorization ua ON au.ixUserAuthorization=ra.ixUserAuthorization "+        
                      " AND ua.ixcustomer=?1 AND ua.ixprogram=?2 AND ua.ixworkpackage=?3AND ua.ixactivity=?4 "+      
                        " AND ua.ixUser=?5) a ",                             userRole,                      
       ixCustomer,
       ixProgram,
       ixWorkPackage, 
       ixActivity,                             ixUser ),                                                                                                           delegate(MySqlDataReader reader)       
 { 

result=Convert.ToBoolean(GetDbValue(reader,"isUserAuthorised"));

                                  });               

返回结果;
}