Essentially, I've run into this error quite a few times and tried to fix it, but to no avail. I've taken a look around, and it seems none of the solutions have helped me. What I'm trying to do is to populate labels with the data within my Access database. However, it will only populate 7 of the required fields, and gives me the error message "Index was outside the bounds of the array". Would anyone be able to take a quick look at my VB code and give me a hand?
Private Sub NR1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NR1.Click
Try
Dim cn As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & My.Application.Info.DirectoryPath.ToString() & "\Flix.Accdb;Persist Security Info=False;")
If cn.State = ConnectionState.Open Then
cn.Close()
End If
cn.Open()
Dim dr1 As OleDbDataReader
Dim com1 As New OleDbCommand
com1.CommandText = "select [Title],[Poster],[Description],[Classification], [Rating], [Stars], [Director], [MakeYear], [Price], [RunningTime] from tbl_newreleases where ID = '" & "1" & "'"
com1.Connection = cn
dr1 = com1.ExecuteReader
If dr1.Read Then
NRTitle.Text = (dr1(9)).ToString()
NRPoster.ImageLocation = (dr1(1)).ToString()
NRDescription.Text = (dr1(2)).ToString()
NRClassification.ImageLocation = (dr1(3)).ToString()
NRStars.ImageLocation = (dr1(4)).ToString()
lblCast.Text = (dr1(5)).ToString
lblDirector.Text = (dr1(6)).ToString
lblYear.Text = (dr1(8)).ToString
lblPrice.Text = (dr1(10)).ToString
lblRunTime.Text = (dr1(7)).ToString
End If
cn.Close()
dr1.Close()
Return
Catch ex As Exception
MsgBox(ex.Message(), MsgBoxStyle.Critical, "Error...")
End Try
End Sub