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.

Recommended Answers

All 3 Replies

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.

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

No worries remember to mark as solved!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.