1.11M Members

Index out of range exception problem

 
0
 

H guys,
I just faced a probelm with my code.It raises an exception.This is the code.

conn = oSubPayItemDescription.GetDbConnection()
            cmd = New OleDbCommand("SELECT [sub_pay_item_quantity].[quantity],[sub_pay_item_unit_rate].[rate] FROM " &
                                   "[sub_pay_item_quantity],[sub_pay_item_unit_rate] WHERE [sub_pay_item_quantity].[sub item]=[sub_pay_item_unit_rate].[sub item] AND " &
                                   "[sub_pay_item_quantity].[sub item]='" & subItem & "' AND [sub_pay_item_quantity].[bridge type]='" & bridgeType & "' " &
                                   "AND [sub_pay_item_quantity].[span]='" & span & "'", conn)

            data_reader = cmd.ExecuteReader()
            If data_reader.HasRows = True Then
                Do While data_reader.Read()
                    payItem = CDbl(data_reader.Item("pay item"))
                    subpayItem = CDbl(data_reader.Item("sub pay item"))
                    subItem = data_reader.Item("sub item")
                    unit = data_reader.Item("unit")
                    bridgeType = data_reader.Item("bridge type")
                    span = (data_reader.Item("span").ToString())
                    quantity = CDbl(data_reader.Item("quantity"))
                    rate = CDbl(data_reader.Item("rate"))

                    RichTextBox1.AppendText(payItem & vbTab & vbTab & " " & " " & subpayItem & vbTab & vbTab & subItem & vbTab & vbTab & " " & _
                                          unit & vbTab & vbTab & " " & " " & " " & " " & bridgeType & vbTab & vbTab & " " & span & vbTab & _
                                            "" & vbTab & " " & quantity & vbTab & rate & vbNewLine)
                Loop
            Else
                MsgBox("Unit rate does not exist", vbCritical, "Bridge Construction Cost Estimate")
            End If

It raises the exception when it reaches the do while loop indicating at pay item.

 
1
 

Hi,

Your SELECT statement that is run in the command is only selecting quantity and rate so the datareader will only have quantity and rate fields.

 
0
 

Ofcourse G Waddell,i fixed it by writing another query.Thanks

 
0
 

No worries remember to mark as solved!

Question Answered as of 8 Months Ago by G_Waddell
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article