Note that there are some explanatory texts on larger screens.

plurals
  1. PODataTable Loop Within a Loop C#
    primarykey
    data
    text
    <p>I have a nice dataset loop working, but I need to run another loop based on an ID in the parent loop.</p> <p>I set up a generic list in a separate class, but I'm totally stumped on how to actually call it. I've Googled it but can't find an example I understand.</p> <p>EDIT:</p> <p>List Code...</p> <pre><code>public class BinList { public static List&lt;Bin&gt; GetById(int binOrderSiteID) { List&lt;Bin&gt; bins = new List&lt;Bin&gt;(); SqlConnection conn; SqlCommand comm; SqlDataReader reader; using (conn = new SqlConnection(myConnectionHere)) { comm = new SqlCommand("dbo.sl_BinsBySite", conn); comm.CommandType = CommandType.StoredProcedure; comm.Parameters.Add(new SqlParameter("@binOrderSiteID", SqlDbType.Int)); comm.Parameters["@binOrderSiteID"].Value = binOrderSiteID; try { conn.Open(); reader = comm.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { Bin b = new Bin(); b.BinQty = reader["binQty"].ToString(); b.BinType = reader["binType"].ToString(); b.BinWasteGroupName = reader["binWasteGroupName"].ToString(); b.BinCollectionFrequencyType = reader["binCollectionFrequencyType"].ToString(); b.BinDeliveryStartDate = reader["binDeliveryStartDate"].ToString(); b.BinEmptyCharge = reader["binEmptyCharge"].ToString(); b.BinRentalCharge = reader["binRentalCharge"].ToString(); b.BinDutyOfCareCharge = reader["binDutyOfCareCharge"].ToString(); b.BinDeliveryCharge = reader["binDeliveryCharge"].ToString(); bins.Add(b); } } } finally { conn.Close(); } } return bins; } } </code></pre> <p>This is a repository for each field </p> <pre><code>public class Bin { public string BinQty { get; set; } public string BinType { get; set; } public string BinWasteGroupName { get; set; } public string BinCollectionFrequencyType { get; set; } public string BinDeliveryStartDate { get; set; } public string BinEmptyCharge { get; set; } public string BinRentalCharge { get; set; } public string BinDutyOfCareCharge { get; set; } public string BinDeliveryCharge { get; set; } } </code></pre> <p>Code to that calls the loops</p> <pre><code>public class PDFCreator { public static int BinOrderID { get; set; } private int binOrderID = 0; public PDFCreator(int intBinOrderID) { //Lots of code here //Data conenection/datatable code here foreach (DataRow row in dt.Rows) { //lots of code here //dont know how to connect up or call the List something?? = BinList.GetById(Convert.ToInt32(row["binOrderSiteID"].ToString())); foreach (//somnething here) } } } </code></pre> <p>Sorry I didn't add my code initially. I didn't want to show it cos I thought it was pants. </p> <p>Any ideas?</p> <p>Cheers, Numb</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload