Datatables & Listbox problem part 2

BillO

Member
Joined
Sep 20, 2010
Messages
9
Programming Experience
Beginner
Hi All,

As per my previous thread I'm having huge trouble getting some data to display in my listboxes.

The btnInvoice gives me "There is no row at position 17."

Obviously my logic has gone awry, as I'm certain there aren't that many items.

Any ideas very welcome!!

Relevant Code below:
VB.NET:
   Private Sub btnInvoice_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnInvoice.Click
       Dim dataAdapter As New OleDb.OleDbDataAdapter(sqlStr, connStr)
       Dim dataAdapter2 As New OleDb.OleDbDataAdapter(sqlStr2, connStr)
       Dim dataAdapter3 As New OleDb.OleDbDataAdapter(sqlStr3, connStr)
       Dim total, invTotal, cost As Double
       Dim fmtStr2 As String = "{0, -30}{1, 8}{2,9:C}{3,10:C}"
       dt.Clear()
       dt2.Clear()
       dt3.Clear()
       dataAdapter.Fill(dt)
       dataAdapter2.Fill(dt2)
       dataAdapter3.Fill(dt3)
       dataAdapter.Dispose()
       For i = 0 To dt3.Rows.Count - 1
           invTotal = 0
           If (HasOrder(dt3.Rows(i)("custID"), dt)) Then 'See HasOrder function
               lstInvoice.Items.Add(String.Format(fmtStr2, "INVOICE FOR:",
"", "", ""))
               lstInvoice.Items.Add(String.Format(fmtStr2, "ITEM DESCRIPTION",
"QTY", "COST", "TOTAL"))
               lstInvoice.Items.Add("-----------------------------""--------""---------""----------")
               lstInvoice.DisplayMember = dt3.Rows(i)("name") And dt3.Rows(i)("street")
And dt3.Rows(i)("City") And ("")
               For j = 0 To dt.Rows.Count - 1
                   If (dt3.Rows(i)("custID") = dt.Rows(j)("custID")) Then
                       For k = 0 To dt2.Rows.Count - 1
                           If dt.Rows(j)("itemID") = dt2.Rows(k)("itemID")
Then
                               total = dt2.Rows(k)("price") * dt.Rows(j)("quantity")
                               invTotal += total
                               cost = total / ("quantity")
                               lstInvoice.DisplayMember = "description"
And "quantity" And cost And total
                           End If
                       Next
                   End If
               Next
               lstInvoice.Items.Add(String.Format(fmtStr2, "", "", "", "----------"))
               lstInvoice.Items.Add(String.Format(fmtStr2, "", "", "", "invTotal"))
               lstInvoice.Items.Add(String.Format(fmtStr2, "", "", "", "----------"))
           End If
       Next
   End Sub

   Function HasOrder(ByVal custID As String, ByVal dt As DataTable)
       Dim found As Boolean = False
       For i = 0 To dt.Rows.Count - 1
           If custID = dt.Rows(i)("custID") Then
               found = True
           End If
       Next
       Return found
   End Function
Cheers :confused:
 
Top Bottom