Search code examples
c#visual-studiowindows-ce

Use List to populate labels C#


I'm creating a device application in VS 2005.

I created a List called "info" and want to populate labels on my form with the values from the List. This is my code:

public List<String> info = new List<String>();
int i = 0;


private void populateinfo()
    {
        conn.Open();
        string query;
        query = "select distinct dp.current_location_code,dci.dest_location_code,dps.order_no,dps.company_id_no,dps.no_of_full_cartons,dps.dc_grv_id_no,s.sku_code from dc_pallet_stock dps, dc_pallet dp,sku s , purch_order_carton_sku pocs , dc_crane_instruc dci where dp.pallet_id_no = dps.pallet_id_no and dps.order_no = pocs.order_no and dps.company_id_no = pocs.company_id_no and dps.carton_code = pocs.carton_code and s.sku_id_no = pocs.sku_id_no and s.company_id_no = dps.company_id_no and dp.pallet_id_no = '" + palletId + "' and dci.pallet_id_no(+) = dps.pallet_id_no";
        OracleCommand cmd = new OracleCommand(query, conn);
        OracleDataReader dr = cmd.ExecuteReader();
        while (dr.Read())
        {
            this.info.Add(dr["order_no"].ToString());
        }
        dr.Close();
        conn.Close();
    }

private void frmInfo_Load(object sender, EventArgs e)
    {
        populateinfo();
        lbl3.Text = this.info[++i];
    {

Im getting error at lbl3.Text = this.info[++i];

Specified argument was out of the range of valid values. Parameter name: index.

This is how I'm testing it at the moment, but at the end I want all the columns in my query to be shown in separate labels, how would I do this. Or is there a better way of doing it? Gridview is no option.

Thanks in advance.


Solution

  • palletId in my select query was incorrect. Please see constructor:

    public List<String> info = new List<String>();
    int i = 0;
    
    public frmInfo(string palletId)
        {
            InitializeComponent();
            this.palletId = palletId;
        }
    
    private void populateinfo()
    {
        conn.Open();
        string query;
        query = "select distinct dp.current_location_code,dci.dest_location_code,dps.order_no,dps.company_id_no,dps.no_of_full_cartons,dps.dc_grv_id_no,s.sku_code from dc_pallet_stock dps, dc_pallet dp,sku s , purch_order_carton_sku pocs , dc_crane_instruc dci where dp.pallet_id_no = dps.pallet_id_no and dps.order_no = pocs.order_no and dps.company_id_no = pocs.company_id_no and dps.carton_code = pocs.carton_code and s.sku_id_no = pocs.sku_id_no and s.company_id_no = dps.company_id_no and dp.pallet_id_no = '" + palletId + "' and dci.pallet_id_no(+) = dps.pallet_id_no";
        OracleCommand cmd = new OracleCommand(query, conn);
        OracleDataReader dr = cmd.ExecuteReader();
        while (dr.Read())
        {
            this.info.Add(dr["order_no"].ToString());
        }
        dr.Close();
        conn.Close();
    }
    
    private void frmInfo_Load(object sender, EventArgs e)
    {
        populateinfo();
        lbl3.Text = this.info[++i];
    {