tags:

views:

31

answers:

1

I'm adding to a combo box an ID and a name that I'm pulling from a database. My problem is that for some reason my loop doesn't end once it reaches the end of the records in the database table. Here's my code:

    For intcount = 0 To dtOrders.Rows.Count - 1
        cmbSearch.Items.Add(dtOrders.Rows(intcount)("EmployeeID").ToString & " " &
           dtOrders.Rows(intcount)("EmployeeLastName").ToString & ", " &
           dtOrders.Rows(intcount)("EmployeeFirstName").ToString)
    Next

Shouldn't the .rows.count - 1 stop it once it reaches the last record? It loops 4 times through.

A: 

Are you sure you're not getting back four times as many rows as you expect in dtOrders?

I'm guessing, from the name "dtOrders", that you're using a query that joins together customer and order information and therefore you will get the customer represented once for each order.

Larry Lustig
You nailed it, sort of. My select statement was pulling another employee ID value from another table that i planned on using later. I thought i could get away with using 1 select statement, oh well. Thanks
Tramd