Hi all! Okay i've been attempting to create this segment of code which is supposed to read from the database; based on search criteria entered, then load them into a form for viewing/editing.
I am able to read the concessionID from the database; however i am then unable to select the name after to insert it into the form.
Could someone point out where i am going wrong in my code and how i may go about fixing my error?
Private Sub btnCSViewCompany_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCSViewCompany.Click
Dim varCompanyID As String
Dim da As SqlDataReader
objCommand.Connection = objConnection
If lstCSCompanyList.SelectedIndex = -1 Then
MsgBox("Please select a company to view.")
ElseIf lstCSCompanyList.SelectedIndex >= 0 Then
Try
objConnection.Open()
Select Case companyType
Case "Concession"
objCommand.CommandText = "SELECT ConcessionID FROM tblConcessions WHERE ConcessionName='" & lstCSCompanyList.SelectedItem & "';"
da = objCommand.ExecuteReader
da.Read()
varCompanyID = (da("ConcessionID"))
MsgBox(varCompanyID)
'Using ID take column detail and place in relevant space
da.Close()
objCommand.CommandText = "SELECT ConcessionName FROM tblConcessions WHERE ConcessionID='" & varCompanyID & "';"
frmConcessions.txtPCompanyName.Text = objCommand.ExecuteNonQuery
frmConcessions.Show()
Me.Dispose()
Case "Garden Centre"
frmGardenCentre.Show()
'will perform similar to case "concessions"
Case "Third Party Company"
frmThirdPartyCompanies.Show()
'will perform similar to case "concessions"
End Select
Finally
objConnection.Close()
End Try
End If
End Sub
The error message that i am getting is:
IndexOutOfRangeException was unhandled
ConcessionName
i have tried an alternative method also by attempting to close and re-open the DataReader; however to no avail :(