Click here to Skip to main content
15,889,216 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am getting this error:
Arraylist' does not contain a definition for 'Add' and no accessible extension method 'Add' accepting a first argument of type 'Arraylist' could be found (are you missing a using directive or an assembly reference?)

Here is the code where the error is popping up:
C#
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;

using EntitiesLayer;

namespace DataLayer
{
    public class D_Dashboard
    {
        readonly SqlConnection connect = new SqlConnection(ConfigurationManager.ConnectionStrings["SistDB"].ConnectionString);

        SqlCommand command;
        SqlDataReader dataReader;

        public void PreferedClients(E_Dashboard entityObject)
        {
            command = new SqlCommand("SPClientes_Preferidos", connect) 
            {
                CommandType = CommandType.StoredProcedure
            };

            connect.Open();
            dataReader = command.ExecuteReader();

            while (dataReader.Read()) 
            {
                entityObject.Profesionales.Add(dataReader.GetString(0));
                entityObject.CantFacturado.Add(dataReader.GetInt32(1)); //Here is where the error pops up
            }

            dataReader.Close();
            connect.Close();
        }
    }
}


As there is references to the E_Dashboard class, here's the class' code:
C#
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EntitiesLayer
{
    public class E_Dashboard
    {
        public ArrayList Profesionales { get; set; } = new ArrayList();

        public ArrayList CantClientes { get; set; } = new ArrayList();

        public ArrayList Clientes { get; set; } = new ArrayList();

        public Arraylist CantFacturado { get; set; } = new ArrayList();

        public static decimal TOTALVENTASDIA { get; set; }

        public int TotalClientes { get; set; }

        public int TotalProfesionales { get; set; }

    }
}


What I have tried:

I tried checking which .Net framework version was the project using, which is the newest available for me (4.7.2). I have a few days checking the internet and my code without getting to a solution, all this because I really don't know what else to do. Thanks in advance.
Posted
Updated 7-Feb-22 12:04pm
v3
Comments
Richard Deeming 8-Feb-22 3:56am    
Don't use ArrayList; it's ancient and should be marked as obsolete. Use the List<T> class instead, specifying the correct type for the data you will be storing in your list.
Héctor Febles 8-Feb-22 9:01am    
Thanks, I will update the code to use the List<t> class instead after some testing is done.

1 solution

In your E_Dashboard class, Arraylist is not the same as ArrayList:
C#
public Arraylist CantFacturado { get; set; } = new ArrayList();
Change that to "ArrayList".
 
Share this answer
 
v2
Comments
CPallini 8-Feb-22 2:14am    
5.
Héctor Febles 8-Feb-22 8:57am    
Thank you very much!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900