Forums
New posts
Search forums
What's new
New posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Search profile posts
C# Community
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Database
OLEDB
Datatables & Listbox problem part 2
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="BillO, post: 127385, member: 30562"] 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: [code] 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 [/code] Cheers :confused: [/QUOTE]
Insert quotes…
Verification
Post reply
Database
OLEDB
Datatables & Listbox problem part 2
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.
Accept
Learn more…
Top
Bottom