473,725 Members | 2,419 Online
Bytes | Software Development & Data Engineering Community
+ 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.Collecti ons.Generic;
using System.Componen tModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows. Forms;
using System.Collecti ons;
using plist;

namespace plist
{
public partial class Form1 : Form
{
public Form1()
{
InitializeCompo nent();
}
private void Form1_Load(obje ct sender, EventArgs e)
{
ArrayList funcList = new ArrayList();
ArrayList arrayData = new ArrayList();
funcList = pgm2.AEdr(array Data);
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(ob ject sender, EventArgs e)
{
}
}
}

Pgm2 ****
using System;
using System.Collecti ons;
using System.Collecti ons.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(o bjList);
for (int i=0; i<funcList.Coun t; i++)
{
adr = funcList[i].ToString(adr);
edr = funcList[i].ToString(edr);
arrayData.Add(a dr);
arrayData.Add(e dr);
}
return arrayData;
}
}
}

Pgm3 ****
using System;
using System.Collecti ons.Generic;
using System.Text;
using System.Collecti ons;
using System.Data;
using System.Data.Sql Client;

namespace plist
{
class pgm3
{
public static ArrayList dataList(ArrayL ist objList)
{
SqlConnection connection = GetConn.GetConn ection();
ArrayList dataList = new ArrayList();
string selectStatement = @"select adr, edr from
wdTable";
SqlCommand selectCommand = new SqlCommand(sele ctStatement,
connection);
SqlDataReader reader;
connection.Open ();
reader = selectCommand.E xecuteReader
(CommandBehavio r.SingleResul t);
while (reader.Read())
{
pgm2 pgm2list = new
pgm2((string)re ader["adr"],(string)reader
["edr"]);
pgm2list.Adr = (string)reader["adr"];
pgm2list.Edr = (string)reader["edr"];
dataList.Add(pg m2list);
}
objList = dataList;
connection.Clos e();
return objList;
}
}
}
Oct 14 '08 #1
1 3505
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
9276
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 by passing a copy, or passing by reference. My understanding of passing by reference (putting the & before a variable during the function declaration) means that the original data is used.
1
2336
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 XMLReader to read passed xml file and extract values that need to be mapped to string buffer. However, in this method I am not able to get the full path (ie., path information from root to this node)
7
2073
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 doesnot know anything about Class A. I'm dealing with legacy code. What is the best way to implement it and have the code change to existing classes such as A and B small? Any
6
2160
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 code, and how do I retrieve the list of all controls and child controls on that form (since I don't think I can just refer to Controls). #region AnyFieldErrors private bool AnyFieldErrors() {
8
6576
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, and then I had other usercontrols simply read this by traversing the class structure: siteClass.userControlClass.specficVariable. That worked fine. The new site I'm working on is a bit different, as I'm using multiple
1
2239
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 of the arraylist are objects of a simple, serializable custom class that allows the recipient listview to reconstruct the dragged listitems. (the contents of the arraylist actually don’t matter…they can be simple integers and the issues in...
8
2594
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; m_ResultArray.Add ( aFoundObject);
12
11098
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. Here is a newbie mistake that I found myself doing (as a newbie), and that even a master programmer, the guru of this forum, Jon Skeet, missed! (He knows this I'm sure, but just didn't think this was my problem; LOL, I am needling him) If...
5
1398
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. 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)
0
8874
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
9393
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9248
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9092
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8072
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 projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6695
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 presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4506
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4775
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2622
muto222
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.