开发者

VB working with SQL DB - end of row count, keeps looping

开发者 https://www.devze.com 2022-12-28 02:34 出处:网络
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. Her

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)("Emp开发者_JS百科loyeeID").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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消