I am trying to add multiple objects to a list (tmpUsers
) but when I try to add the second object I get into the catch block? Can someone see if I am doing it the right way and help me understand where I am going wrong?
public List<User> GetFilteredUsers(long CompanyKey, int sitekey, int filtertype=4, string filtervalue="", UserRequestContext requestContext = null)
{
List<User> tmpUsers = new List<User>();
Database db = null;
IDataReader dr = null;
DbCommand dbCommand = null;
try
{
db = DatabaseFactory.CreateDatabase("vaultDataConfiguration");
dbCommand = db.GetStoredProcCommand("GetFilteredUsers");
db.AddInParameter(dbCommand, "@CompanyKey", DbType.Int32, CompanyKey);
db.AddInParameter(dbCommand, "@Sitekey", DbType.Int32, sitekey);
db.AddInParameter(dbCommand, "@FilterType", DbType.Int32, filtertype);
db.AddInParameter(dbCommand, "@FiterValue", DbType.String, filtervalue);
dr = db.ExecuteReader(dbCommand);
User tmpUser = new User();
while (dr.Read())
{
tmpUser.GroupName = dr["groupName"] != DBNull.Value ? dr["groupName"].ToString() : "";
tmpUsers.Add(tmpUser);
}
tmpUser = new User();
tmpUser.CompanyUdidDescription = dr["companyUDIDDescription"] != DBNull.Value ? dr["companyUDIDDescription"].ToString() : "";
tmpUsers.Add(tmpUser);
return tmpUsers;
}
catch (Exception ex)
{
LogWriter.WriteAuditLog(ex.Message, LogLevel.ERROR, exception: ex, _event: "UserDAO->GetFilteredUserDetails", requestContext: requestContext);
throw;
}
finally
{
if (dr != null)
{
dr.Close();
dr.Dispose();
}
}
}