From: JB on
Hello

I am passing an arraylist to be filled with data from pgm1 to pgm2 to
pgm3 where it gets filled, then I pass it back from pgm3 to pgm2 to pgm1
where I will use the data from arraylist. The problem is that I am having
trouble passing the arraylist back and forth. Below is a sample of what I am
trying to do and I would like to know where I am going wrong?

***pgm1:
private void Form1_Load(object sender, System.EventArgs e)
{
string Adr;
string Edr;
int IRows;
ArrayList funcList;
ArrayList arrayData;
arrayData.Add("Adr");
arrayData.Add("Edr");
arrayData.Add("IRows");
funcList.Add("Adr");
funcList.Add("Edr");
funcList.Add("IRows");
funcList = pgm2.AEdr(ArrayList arrayData);
label1.Text = "there are " + funcList.Count + "rows";
}

***pgm2:
public void AEdr(ArrayList arrayData)
{
ArrayList funcList = new ArrayList();
ArrayList objList = new ArrayList();
funcList = pgm3.dataList(objList);
for(int i = 0; i < objList.Count; i++)
{
string adr;
string edr;
int irows;
funcList.adr[i] = objList.adr[i];
funcList.edr[i] = objList.edr[i];
funcList.irows = irows++;
arrayData.Add(funcList);
}
return arrayData;
}
***pgm3:
public ArrayList dataList(ArrayList objList)
{
ArrayList(objList) getList = new ArrayList (objList);
SqlConnection connection = new
SqlConnection("Data Source=localhost;Initial Catalog=sDatabase;Integrated
Security=True");
string selectStatement = @"select adr, edr from wdTable";
SqlCommand selectCommand = new SqlCommand(selectStatement,
connection);
SqlDataReader reader;
connection.Open();
reader = selectCommand.ExecuteReader(CommandBehavior.SingleResult);
while (reader.Read())
{
objList getList = new objList
((string)reader["adr"],(string)reader["edr"]);
getList.Adr = (string)reader["adr"];
getList.Edr = (string)reader["edr"];
objList.Add(getList);
}
reader.Close;
connection.Close();
return objList;
}

Thanks
JB

--
JB
From: Peter Duniho on
On Fri, 10 Oct 2008 19:29:01 -0700, JB <JB(a)discussions.microsoft.com>
wrote:

> Hello
>
> I am passing an arraylist to be filled with data from pgm1 to pgm2 to
> pgm3 where it gets filled, then I pass it back from pgm3 to pgm2 to pgm1
> where I will use the data from arraylist. The problem is that I am
> having
> trouble passing the arraylist back and forth. Below is a sample of what
> I am
> trying to do and I would like to know where I am going wrong?

At the very least, if something doesn't work, you need to explain in what
way it doesn't work. Ideally, you would post a concise-but-complete code
sample.

The code you posted won't even compile without modification. In
"***pgm1", your call to "AEdr(ArrayList arrayData)" includes the type
specifier "ArrayList" when it should only include the actual variable
being passed ("arrayData").

That _might_ be the issue you're having, or maybe it's something else.
You haven't provided nearly enough detail for anyone to know.

Pete
From: Nathan Sokalski on
Peter is definitely correct in his statement, but I am noticing one other
thing in your code. In pgm2 and pgm3, you return the parameter that you pass
in. This is not necessary, since an ArrayList is an Object and is therefore
a reference variable. So rather than return a value to assign to a variable
in the calling function, just make the function void. In the function,
modify the ArrayList parameter as you would have otherwise, and then when
you return to the calling function, it will be updated, since it is really
the same variable. I am not always the best person at explaining things, but
if you do not already, you should learn the concept of and difference
between value and reference variables, it is a very important part of
object-oriented programming. Good Luck!
--
Nathan Sokalski
njsokalski(a)hotmail.com
http://www.nathansokalski.com/

"Peter Duniho" <NpOeStPeAdM(a)nnowslpianmk.com> wrote in message
news:op.uiuam3pi8jd0ej(a)petes-computer.local...
> On Fri, 10 Oct 2008 19:29:01 -0700, JB <JB(a)discussions.microsoft.com>
> wrote:
>
>> Hello
>>
>> I am passing an arraylist to be filled with data from pgm1 to pgm2 to
>> pgm3 where it gets filled, then I pass it back from pgm3 to pgm2 to pgm1
>> where I will use the data from arraylist. The problem is that I am
>> having
>> trouble passing the arraylist back and forth. Below is a sample of what
>> I am
>> trying to do and I would like to know where I am going wrong?
>
> At the very least, if something doesn't work, you need to explain in what
> way it doesn't work. Ideally, you would post a concise-but-complete code
> sample.
>
> The code you posted won't even compile without modification. In
> "***pgm1", your call to "AEdr(ArrayList arrayData)" includes the type
> specifier "ArrayList" when it should only include the actual variable
> being passed ("arrayData").
>
> That _might_ be the issue you're having, or maybe it's something else.
> You haven't provided nearly enough detail for anyone to know.
>
> Pete


From: JTC^..^ on
On 11 Oct, 03:29, JB <J...(a)discussions.microsoft.com> wrote:
> Hello
>
>     I am passing an arraylist to be filled with data from pgm1 to pgm2 to
> pgm3 where it gets filled, then I pass it back from pgm3 to pgm2 to pgm1
> where I will  use the data from arraylist.  The problem is that I am having
> trouble passing the arraylist back and forth.  Below is a sample of what I am
> trying to do and I would like to know where I am going wrong?
>
> ***pgm1:
> private void Form1_Load(object sender, System.EventArgs e)
> {
>     string Adr;
>     string Edr;
>     int IRows;
>     ArrayList funcList;
>     ArrayList arrayData;
>     arrayData.Add("Adr");
>     arrayData.Add("Edr");
>     arrayData.Add("IRows");
>     funcList.Add("Adr");
>     funcList.Add("Edr");
>     funcList.Add("IRows");
>     funcList = pgm2.AEdr(ArrayList arrayData);
>     label1.Text = "there are "  + funcList.Count + "rows";
>
> }
>
> ***pgm2:
> public void AEdr(ArrayList arrayData)
> {
>     ArrayList funcList = new ArrayList();
>     ArrayList objList = new ArrayList();
>     funcList = pgm3.dataList(objList);
>     for(int i = 0; i < objList.Count; i++)
>         {
>             string adr;
>             string edr;
>             int irows;
>             funcList.adr[i] = objList.adr[i];
>             funcList.edr[i] = objList.edr[i];
>             funcList.irows = irows++;
>             arrayData.Add(funcList);
>         }
>         return arrayData;}
>
> ***pgm3:
> public ArrayList dataList(ArrayList objList)
> {
>     ArrayList(objList) getList = new ArrayList (objList);
>     SqlConnection connection = new
>     SqlConnection("Data Source=localhost;Initial Catalog=sDatabase;Integrated
>         Security=True");
>     string selectStatement = @"select adr, edr from wdTable";
>     SqlCommand selectCommand = new SqlCommand(selectStatement,
>         connection);
>     SqlDataReader reader;
>     connection.Open();
>     reader = selectCommand.ExecuteReader(CommandBehavior.SingleResult);
>     while (reader.Read())
>     {
>         objList getList = new objList
> ((string)reader["adr"],(string)reader["edr"]);
>         getList.Adr = (string)reader["adr"];
>         getList.Edr = (string)reader["edr"];
>         objList.Add(getList);
>     }
>     reader.Close;
>     connection.Close();
>     return objList;
>
> }
>
>     Thanks
>     JB
>
> --
> JB

As pointed out in the previous post you need to be explain the problem
you are having. However, my mind reading powers are telling me that
you are designing a tiered solution, pgm1 pgm2 pgm3. being the the UI,
BLL, DAL respectively.

My code deciphering machine has produced a consise example based on a
predicted nTier architecture: CodeExample example =
RandomCodeInterpreter.Refactor(randomCode, Architecture.nTier) ;) I
it's working and has managed to give you a good idea. Joking aside
though, in the future please be more consise with your posts.

UI

public partial class OrderForm : Form
{
public OrderForm()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
this.lbCustomers.DataSource = Customer.GetCustomers();
}
}

BLL

public class Customer
{
private string _address;
public string Address
{
get { return _address; }
set { _address = value; }
}

private string _emailAddress;
public string EmailAddress
{
get { return _emailAddress; }
set { _emailAddress = value; }
}

public static List<Customer> GetCustomers()
{
return CustomerDALC.GetCustomerData();
}
}

DAL

public class CustomerDALC
{
public static List<Customer> GetCustomerData()
{
List<Customer> getList = new List<Customer>();

SqlConnection connection = new SqlConnection("Data
Source=localhost;Initial Catalog=sDatabase;Integrated Security=True");
string selectStatement = @"select adr, edr from wdTable";
SqlCommand selectCommand = new SqlCommand(selectStatement,
connection);
SqlDataReader reader;
connection.Open();
reader =
selectCommand.ExecuteReader(CommandBehavior.SingleResult);
while (reader.Read())
{
Customer customer = new Customer();
customer.Address = (string)reader["adr"];
customer.EmailAddress = (string)reader["edr"];
getList.Add(customer);
}
reader.Close();
connection.Close();

return getList;
}
}
From: Davita on
When you pass a class reference as a parameter to a method, there is no need
for the method to return the arraylist object with return keyword, instead,
the changes made in calling method will be reflected on the caller method
too. for example

ArrayList aa = new ArrayList();
InsertOne(aa);
//Now 1 is inserted into aa
Console.WriteLine(aa[0]);

public void InsertOne(ArrayList ar)
{
ar.Add(1);
}

"JB" <JB(a)discussions.microsoft.com> wrote in message
news:BAB1DB13-56DA-40B4-8017-DC3EB9E3B0CA(a)microsoft.com...
> Hello
>
> I am passing an arraylist to be filled with data from pgm1 to pgm2 to
> pgm3 where it gets filled, then I pass it back from pgm3 to pgm2 to pgm1
> where I will use the data from arraylist. The problem is that I am
> having
> trouble passing the arraylist back and forth. Below is a sample of what I
> am
> trying to do and I would like to know where I am going wrong?
>
> ***pgm1:
> private void Form1_Load(object sender, System.EventArgs e)
> {
> string Adr;
> string Edr;
> int IRows;
> ArrayList funcList;
> ArrayList arrayData;
> arrayData.Add("Adr");
> arrayData.Add("Edr");
> arrayData.Add("IRows");
> funcList.Add("Adr");
> funcList.Add("Edr");
> funcList.Add("IRows");
> funcList = pgm2.AEdr(ArrayList arrayData);
> label1.Text = "there are " + funcList.Count + "rows";
> }
>
> ***pgm2:
> public void AEdr(ArrayList arrayData)
> {
> ArrayList funcList = new ArrayList();
> ArrayList objList = new ArrayList();
> funcList = pgm3.dataList(objList);
> for(int i = 0; i < objList.Count; i++)
> {
> string adr;
> string edr;
> int irows;
> funcList.adr[i] = objList.adr[i];
> funcList.edr[i] = objList.edr[i];
> funcList.irows = irows++;
> arrayData.Add(funcList);
> }
> return arrayData;
> }
> ***pgm3:
> public ArrayList dataList(ArrayList objList)
> {
> ArrayList(objList) getList = new ArrayList (objList);
> SqlConnection connection = new
> SqlConnection("Data Source=localhost;Initial
> Catalog=sDatabase;Integrated
> Security=True");
> string selectStatement = @"select adr, edr from wdTable";
> SqlCommand selectCommand = new SqlCommand(selectStatement,
> connection);
> SqlDataReader reader;
> connection.Open();
> reader = selectCommand.ExecuteReader(CommandBehavior.SingleResult);
> while (reader.Read())
> {
> objList getList = new objList
> ((string)reader["adr"],(string)reader["edr"]);
> getList.Adr = (string)reader["adr"];
> getList.Edr = (string)reader["edr"];
> objList.Add(getList);
> }
> reader.Close;
> connection.Close();
> return objList;
> }
>
> Thanks
> JB
>
> --
> JB