1,105,242 Community Members

Index out of range exception problem

Member Avatar
Nebil
Junior Poster in Training
62 posts since Apr 2013
Reputation Points: 5 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
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.

Member Avatar
G_Waddell
Practically a Posting Shark
821 posts since Nov 2009
Reputation Points: 131 [?]
Q&As Helped to Solve: 137 [?]
Skill Endorsements: 13 [?]
 
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.

Member Avatar
Nebil
Junior Poster in Training
62 posts since Apr 2013
Reputation Points: 5 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
G_Waddell
Practically a Posting Shark
821 posts since Nov 2009
Reputation Points: 131 [?]
Q&As Helped to Solve: 137 [?]
Skill Endorsements: 13 [?]
 
0
 

No worries remember to mark as solved!

Question Answered as of 5 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