DataTable search problem RRS feed

  • Question

  • User1510859543 posted

    We are building a DataTable and then using it in code to search for a labor rate to use in a dataset row.  However, when a matching record is not found in the DataTable and we try to refer to a column in the row it fails with the error message below.

    "Index was outside the bounds of the array."

    Below is a summation of the code.

                'Create the DataTable for labor rates to use in lookup on lines
                Dim dt As New DataTable()
                'Create the columns 
                Dim dcLaborType As New DataColumn("LaborType", GetType(String))
                Dim dcLaborRate As New DataColumn("LaborRate", GetType(String))
                Dim dcLaborTax As New DataColumn("LaborTax", GetType(String))
                Dim strLaborType As String = ""
                Dim strLaborRate As String = ""
                Dim strLaborTax As String = ""
                'Add the columns to the DataTable's column collection
    	...filled all rows of DataTable
                 'get the labor rate
                 Dim rowRate As DataRow() = dt.Select("LaborType = '" & strModLbrTy & "'")
                 dblLaborRate = rowRate(0).Item(1)    <-- code fails here with error message

    Wednesday, July 27, 2016 8:58 PM