On 11 Oct, 03:29, JB <J...@discussions.microsoft.comwrote:
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.Single Result);
* * 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<CustomerGetCustomers()
{
return CustomerDALC.GetCustomerData();
}
}
DAL
public class CustomerDALC
{
public static List<CustomerGetCustomerData()
{
List<CustomergetList = 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.Single Result);
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;
}
}