I have a nice dataset loop working, but I need to run another loop based on an ID in the parent loop.
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.
EDIT:
List Code…
public class BinList
{
public static List<Bin> GetById(int binOrderSiteID)
{
List<Bin> bins = new List<Bin>();
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;
}
}
This is a repository for each field
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 to that calls the loops
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)
}
}
}
Sorry I didn’t add my code initially. I didn’t want to show it cos I thought it was pants.
Any ideas?
Cheers,
Numb
To call BinList GetById