ArrayList does not except arguments passed Multidimensional Array

Original Question
http://www.experts-exchange.com/Programming/Languages/C_Sharp/Q_22968639.html
--------------------------------------------------
I receive 3 errors when I try to use the code provided in the soloution
Error      1      The type or namespace name 'Data' could not be found (are you missing a using directive or an assembly reference?)      C:\Documents and Settings\tcbea\Desktop\VS Projects Nathan\SITS-SQT\SITS-SQT\SQT.cs      4433      32      SITS-SQT
Error      2      The best overloaded method match for 'System.Collections.ArrayList.Add(object)' has some invalid arguments      C:\Documents and Settings\tcbea\Desktop\VS Projects Nathan\SITS-SQT\SITS-SQT\SQT.cs      4433      21      SITS-SQT
Error      3      Argument '1': cannot convert from 'Data' to 'object'      C:\Documents and Settings\tcbea\Desktop\VS Projects Nathan\SITS-SQT\SITS-SQT\SQT.cs      4433      28      SITS-SQT
--------------------------------------------------------------------------------------------------------------------
Segment of Code that generates error
ArrayList al = new ArrayList();
TrypsimAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Jaime OlivaresConnect With a Mentor Software ArchitectCommented:
OK, you application had a Main() method, in Program.cs
In clrtest.cs, you have a Main() method again, just remove it. It was just put by the answerer to give an example.
0
 
RedKelvinCommented:
Hi, put this at the top of your code
using System.Data

Open in new window

0
 
Jaime OlivaresSoftware ArchitectCommented:
appears to be you need the following directive at the top of SQT.cs:

using clrtest;
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
TrypsimAuthor Commented:
using System.Data;  // Included in my libraries

The actual line of code that generates the error is  -->  al.Add(new Data (HName, LstLgn));

I annotated that incorrectly in the question.

Thanks for help though :-D



0
 
Jaime OlivaresSoftware ArchitectCommented:
Data class belongs to the clrtest namespace.
Have you followed my suggestion?
0
 
Jaime OlivaresSoftware ArchitectCommented:
by the way, Data is not a good name for a class, since there is a Data namespace in .net
Try to change it.
0
 
TrypsimAuthor Commented:
I am trying to figure out how to add the clrtest library.  Do I need to add a refrence?
0
 
Jaime OlivaresSoftware ArchitectCommented:
>>I am trying to figure out how to add the clrtest library.  Do I need to add a refrence?
Not at all.  in the previous question you mentioned, the answer proposed by evilrix was near to the Program class, in the program.cs file.
Just include the .cs file with the Data class inside your code. You don't need any other reference.
Notice the Data class was define inside the 'clrtest' namespace
0
 
TrypsimAuthor Commented:
I dont have a clrtest namespace that I have created?  I am a bit confused lets bring the code that was provided into this segment.  I do not see anywhere in the final code segment where clrtest was defined.  I am probably missing something here but please continue to help it is greatly appreciated.
private ArrayList Button_1_Click(object sender, EventArgs e)
{
//////////////////////////////////////////////////////////////////////
        // Create new array
        ArrayList al = new ArrayList();
//////////////////////////////////////////////////////////////////////
 
        string OUDN = txtTargetList_Path.Text;
        try
        {
            DirectoryEntry entry = new DirectoryEntry("LDAP://" + OUDN);
            DirectorySearcher DirSearch = new DirectorySearcher(entry);
            DirSearch.Filter = "(objectClass=computer)";
            DirSearch.PageSize = 100000;
 
            foreach(SearchResult results in DirSearch.FindAll())
            {
                string Line = "";
                string HName = "";
                string LstLgn = "";
                
                foreach(string Value in                                 results.Properties.PropertyNames)
                {
                    if(results.Properties[Value]!=null)
                    {
                        if (Value == "name")
                        {
                            HName = (string)results.Properties[Value][0];
                        }
                        if(Value == "lastlogon")
                        {
                            long lastLogon = (long)results.Properties[Value][0];
                            LstLgn = DateTime.FromFileTime(lastLogon).ToString(); 
                        }
                    }
                }
                Line = HName + "," + LstLgn;
                listBox1.Items.Add(Line);
 
//////////////////////////////////////////////////////////////
                // Add name/logintime to array
                al.Add(new Data(HName, LstLgn));
//////////////////////////////////////////////////////////////
            }
        }
        catch (IOException Iox)
        {
            lstErrorLog.Items.Add(Iox.Data.ToString());
        }
        catch (DirectoryServicesCOMException ex)
        {
            lstErrorLog.Items.Add(ex.Message.ToString());
        }
 
//////////////////////////////////////////////////////////////////////
        // Return array
        return al;
//////////////////////////////////////////////////////////////////////
}

Open in new window

0
 
Jaime OlivaresSoftware ArchitectCommented:
How is Data defined?
I assume it is defined exactly like in the previous question, that is, inside a namespace called clrtest.
 
0
 
TrypsimAuthor Commented:
Ok I see what you are saying now apparently he provided a class object for clrtest.  I added it as an existing file to my project and used the using clrtest.  I now have another error?
--------------
Error      1      Program 'C:\Documents and Settings\tcbea\Desktop\VS Projects Nathan\SITS-SQT\SITS-SQT\obj\Debug\SITS-SQT.exe' has more than one entry point defined: 'SITS_SQT.Program.Main()'      C:\Documents and Settings\tcbea\Desktop\VS Projects Nathan\SITS-SQT\SITS-SQT\Program.cs      13      21      SITS-SQT
Error      2      Program 'C:\Documents and Settings\tcbea\Desktop\VS Projects Nathan\SITS-SQT\SITS-SQT\obj\Debug\SITS-SQT.exe' has more than one entry point defined: 'clrtest.Program.Main(string[])'      C:\Documents and Settings\tcbea\Desktop\VS Projects Nathan\SITS-SQT\SITS-SQT\clrtest.cs      51      21      SITS-SQT
-----------
0
 
TrypsimAuthor Commented:
The original question was just to show me how to store the results in an array from you query to Active Directory.  2 objects need to be stored The Name of the Computer and the Last Login Date.
---------------------------------------
The code snipet I sent to the original question is posted in this question.  I just want to store the information in the array and pass it to the calling function.
--------------------------------------
I am wrather new to programming in C# and have only picked up things on my own.  Thanks for the help.
private void Button_1_Click(object sender, EventArgs e)
        {
                string OUDN = txtTargetList_Path.Text;
                try
                {
                    DirectoryEntry entry = new DirectoryEntry("LDAP://" + OUDN);
                    DirectorySearcher DirSearch = new DirectorySearcher(entry);
                    DirSearch.Filter = "(objectClass=computer)";
                    DirSearch.PageSize = 100000;
 
                    foreach(SearchResult results in DirSearch.FindAll())
                    {
                        string Line = "";
                        string HName = "";
                        string LstLgn = "";
                        
                        foreach(string Value in results.Properties.PropertyNames)
                        {
                            if(results.Properties[Value]!=null)
                            {
                                if (Value == "name")
                                {
                                    HName = (string)results.Properties[Value][0];
                                }
                                if(Value == "lastlogon")
                                {
                                    long lastLogon = (long)results.Properties[Value][0];
                                    LstLgn = DateTime.FromFileTime(lastLogon).ToString(); 
                                }
                            }
                        }
                        Line = HName + "," + LstLgn;
                        listBox1.Items.Add(Line);
                    }
                }
                catch (IOException Iox)
                {
                    lstErrorLog.Items.Add(Iox.Data.ToString());
                }
                catch (DirectoryServicesCOMException ex)
                {
                    lstErrorLog.Items.Add(ex.Message.ToString());
                }
        }

Open in new window

0
 
TrypsimAuthor Commented:
Spent alot of time assisting me with this issue, I really do apprediate the help.  Made my issue alot easier to understand.  Thanks again!!!
0
All Courses

From novice to tech pro — start learning today.