DataGridView not recognizing Dataset?

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)
        Try
            clsDE = New CalTableClasses.CalibrationClasses.DETAILS_Equipment

            InitializeErrorClass(EH)
            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
                        Next
                    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

Screenshot.jpg
BlakeMcKennaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Shaun KlineLead Software EngineerCommented:
The image and code do not provide enough information. How do you have your datagridview configured? Are you manually defining the columns or are you auto-generating them? If auto-generating them, does your query return 19+ columns of data? If manually defining them, have you added 19+ columns to it? (The plus sign is because, according to your code, you have 26 columns of data to display.)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
BlakeMcKennaAuthor Commented:
Shaun,

You just sparked a thought. The grid is empty (no columns/rows). I forgot to set the "AutoGenerateColumns" property. I inserted that statement and it worked as it should!

Thanks!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.