We help IT Professionals succeed at work.
Get Started

DataGridView not recognizing Dataset?

BlakeMcKenna asked
Last Modified: 2014-08-14
I have a function that returns a single row from a SQL Server Database. I'm getting the following error message: "Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index" on the line marked "Error occurs here". That tells me that even though the dataset contains a valid record, for some reason it's not being assigned to the DataGridView. What's up with that? See attached image.

    Private Function GetDetailRecords(ByVal iEquipmentID As Integer)
            clsDE = New CalTableClasses.CalibrationClasses.DETAILS_Equipment

            BL.GetDetailsEquipmentRecord(iEquipmentID, clsDE, EH)

            If EH.Success Then
                dgvComponents.DataSource = Nothing

                If EH.ErrorMessage = "" Then
                    If EH.DataSet.Tables(0).Rows.Count > 0 Then
                        dgvComponents.DataSource = EH.DataSet.Tables(0)
                        dgvComponents.Columns(18).Visible = False     'Error occurs here
                        dgvComponents.Columns(19).Visible = False
                        dgvComponents.Columns(20).Visible = False
                        dgvComponents.Columns(21).Visible = False
                        dgvComponents.Columns(22).Visible = False
                        dgvComponents.Columns(23).Visible = False
                        dgvComponents.Columns(24).Visible = False
                        dgvComponents.Columns(25).Visible = False

                        For Each row As DataRow In EH.DataSet.Tables(0).Rows
                            If Not IsDBNull(row(1)) Then
                                iSeqNO = row(1)
                            End If
                    End If
                End If
            End If

        Catch ex As Exception
            EH.ErrorMessage = "GetDetailRecords() - " & ex.Message & "...Contact Engineering!" & "~E"
        End Try

        Return EH
    End Function

Open in new window

Watch Question
Lead Software Engineer
This problem has been solved!
Unlock 1 Answer and 2 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE