473,473 Members | 1,569 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to pass extract data from an ArrayList passed back from a clas

Hello

My pgm1 (User Interface Level) passes an empty ArrayList to pgm2
(Business Logic Level). pgm2 then calls pgm3 (Data Access Level) to populate
the ArrayList.

Question1: When pgm2 gets the ArrayList back from pgm3 how to extract and
separate the fields out fo the ArrayLists?

Question2: When pgm3 gets ArrayList back from pgm2 how to separate the
fields out of the Arraylist and assign it to variables that will be process
later on?

Below is the code simplified:

Pgm1 ****
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using plist;

namespace plist
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
ArrayList funcList = new ArrayList();
ArrayList arrayData = new ArrayList();
funcList = pgm2.AEdr(arrayData);
string adr = "";
string edr = "";
for (int i = 0; i < funcList.Count; i++)
{
"adr" + i = funcList[i].ToString(adr);
"edr" + i = funcList[i].ToString(edr);
}
//label1.Text = "there are " + funcList.Count + " rows";
}
private void label1_Click(object sender, EventArgs e)
{
}
}
}

Pgm2 ****
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;

namespace plist
{
class pgm2
{
private string adr;
private string edr;
public pgm2(string adr, string edr)
{
Adr = adr;
Edr = edr;
}
public string Adr
{
get { return adr; }
set { adr = value; }
}
public string Edr
{
get { return edr; }
set { edr = value; }
}
public static ArrayList AEdr(ArrayList arrayData)
{
string adr = "";
string edr = "";
ArrayList funcList = new ArrayList();
ArrayList objList = new ArrayList();
funcList = pgm3.dataList(objList);
for (int i=0; i<funcList.Count; i++)
{
adr = funcList[i].ToString(adr);
edr = funcList[i].ToString(edr);
arrayData.Add(adr);
arrayData.Add(edr);
}
return arrayData;
}
}
}

Pgm3 ****
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Data;
using System.Data.SqlClient;

namespace plist
{
class pgm3
{
public static ArrayList dataList(ArrayList objList)
{
SqlConnection connection = GetConn.GetConnection();
ArrayList dataList = new ArrayList();
string selectStatement = @"select adr, edr from
wdTable";
SqlCommand selectCommand = new SqlCommand(selectStatement,
connection);
SqlDataReader reader;
connection.Open();
reader = selectCommand.ExecuteReader
(CommandBehavior.SingleResul t);
while (reader.Read())
{
pgm2 pgm2list = new
pgm2((string)reader["adr"],(string)reader
["edr"]);
pgm2list.Adr = (string)reader["adr"];
pgm2list.Edr = (string)reader["edr"];
dataList.Add(pgm2list);
}
objList = dataList;
connection.Close();
return objList;
}
}
}
Oct 14 '08 #1
1 3492
On Tue, 14 Oct 2008 16:11:03 -0700, JB <JB@discussions.microsoft.com>
wrote:
Hello

My pgm1 (User Interface Level) passes an empty ArrayList to pgm2
(Business Logic Level). pgm2 then calls pgm3 (Data Access Level) to
populate
the ArrayList.
Actually, no it doesn't. The pgm3 class never uses the ArrayList that was
passed to it. It just ignores it.
Question1: When pgm2 gets the ArrayList back from pgm3 how to extract
and
separate the fields out fo the ArrayLists?
Well, you can design it however you like. But you do need to make sure
that the code retrieving the data uses the same technique as the code
adding the data. Right now you add instances of the pgm2 class, but then
try to retrieve them as if they were alternating elements in the
ArrayList. Instead, you should just cast each element to pgm2 and
retrieve the properties directly.

That said...
Question2: When pgm3 gets ArrayList back from pgm2 how to separate the
fields out of the Arraylist and assign it to variables that will be
process
later on?
Do you mean "when pgm1 gets ArrayList back from pgm2"? Otherwise, your
question doesn't make sense.

It seems to me that the code you posted is just plain bogus. It's not
"simplified", it's been contorted into something that couldn't possibly
work. Don't post code like that. It's not useful. And the code you
posted looks to me as though it might not even run; you are passing the
previous result of a call to ToString() to the next call. At best, the
argument would be ignored, but it may actually throw an exception
complaining about a bad format string.

It seems to me that there are at least two major things you need to figure
out:

-- do you want the lower level code to populate an existing ArrayList,
or do you just want the lower level code to return a new one. Right now,
you are passing down an ArrayList that is only used in the middle step.
The lowest level code (in pgm3) ignores it completely; you wind up
allocating not one, but _two_ ArrayList instances that are simply never
used. That's just dopey.

-- do you want to store the data in a single class, or do you want
alternate elements in the ArrayList to track each field being returned?
Right now, the lowest level creates an instance of a single class (the
pgm2 class), but the middle level tries (and fails) to break the two
properties of that class into alternating elements of the output ArrayList.

Finally, you should go back and reread the advice that was given to you in
your previous question. In particular, if you're passing an ArrayList to
a method, it can just modify that ArrayList without having to return the
instance reference. The caller will just use the reference it already
had. Conversely, if you want to return a new ArrayList instance, don't
even bother passing an existing one in. That's wasteful and pointless.

Pete
Oct 14 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Randell D. | last post by:
Folks, I've asked this before but never got any response but its important and I thought I'd pitch it again (hopefully a bit clearer)... One can pass data from one function to another either...
1
by: Srini | last post by:
Hi, I am working on a project and a portion of which involves receiving xml files on internet, extract values to build a string and pass that string to legacy system. I am planning on using...
7
by: liyang3 | last post by:
Hi, I have Class A, B and C. Class A has an instance of B. Class B has an instance of C. In the instance of C, it generates some data that need to be passed back to Class A. But Class C...
6
by: Vern | last post by:
I'd like to make the following a generic method that all my forms can call to validate all the fields on the form. So how do I pass the form object that is represented as "this" in the following...
8
by: darrel | last post by:
I'm still trying to fully understand how best to pass variables between pages/usercontrols/each other. On a current site I've done, I've had one userControl do the logic and set the variable,...
1
by: Neil West | last post by:
I’m trying to drag & drop listview items between two instances of my app. The actual data that’s passed in DoDragDrop is an arraylist that’s been serialized to a memorystream. The contents...
8
by: Guy | last post by:
Is there a better way to search identical elements in a sorted array list than the following: iIndex = Array.BinarySearch( m_Array, 0, m_Array.Count, aSearchedObject ); aFoundObject= m_Array;...
12
by: raylopez99 | last post by:
Keywords: scope resolution, passing classes between parent and child forms, parameter constructor method, normal constructor, default constructor, forward reference, sharing classes between forms....
5
by: =?Utf-8?B?SkI=?= | last post by:
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. ...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.