Using List<T> elements as variable in query

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Wesley Hader
    New Member
    • Nov 2011
    • 30

    Using List<T> elements as variable in query

    I am trying to query an Informix database using a List<T> collection's elements as variables. I can build the list and connect to the database, but I am unsure how to iterate through the list and query the database for each item in the collection.

    My list is of type string, and contains Order Numbers. I want to query item information for each order number in the list.

    I hope this is enough information. Thank you for your help.

    Wes
  • Wesley Hader
    New Member
    • Nov 2011
    • 30

    #2
    I'm Lost!

    This is what I have so far.... As I'm sure you can probably tell, I am just trying to feel my way through this. I have only been coding in C# for a couple of weeks.

    Code:
     
    List<string> orders = new List<string>();
    
                foreach (DataGridViewRow dr in ordersTable.Rows)
                {
                    orders.Add(dr.Cells["szPOSOrderNumber"].Value.ToString());
                }
    
    IfxCommand cmd = new IfxCommand("SELECT item_code, item_description FROM ioq_hdr WHERE ioqh_nbr = @orderNumber", conn);
    
    
                for (int i = 0; i < orders.Count(); i++)
    			{
        			Item orderItem = new Item();
                    
                    int ioqh_nbr = int.Parse(orders.ElementAt(i));
    
                    cmd.ExecuteReader();
                    
                    orderItem.itemCode = "ABC123";
    
    			}

    Comment

    Working...