Robert Bee
Robert Bee

Reputation: 19

vb.net: loops for 49 iterations but no more?

enter image description hereI want to loop through an excel spreadsheet, getting the account number and then loop through a datatable using this account to find the max, or last, line number. It's getting the linenumber where the problem is....

I'm using the code below, which works for 49 records but nothing above, and errors with an 'ODBC error'. The 49th invoicenumber seems fine to look at, 70330, and, if I remove it, it just errors on the next invoicenumber.

Also, if I lift the sql out and paste into MSAccess, it works.

Any pointers would be appreciated.

        'Find Line Number
        Dim Query2 As String = "SELECT PUB_invoice2.[invoice-number], Max(PUB_invoice2.[line-number]) AS [MaxOfline-number] FROM PUB_invoice2 GROUP BY PUB_invoice2.[invoice-number] HAVING (((PUB_invoice2.[invoice-number])=" & invoiceNumber & "));"
        Dim cmd2 As New OleDbCommand(Query2, cnn)
        Dim TheDataReader2 As OleDbDataReader = cmd2.ExecuteReader()

        While TheDataReader2.Read()
            invoiceLine = TheDataReader2("MaxOfline-number")
        End While

        TheDataReader2.Close()

Rob

Upvotes: 1

Views: 44

Answers (0)

Related Questions