I've got labels on my form using the following "Shift1Time1Label" to "Shift1Time8Label".
I'm trying to get information from a access database and change the text of the labels.
I'm getting the information, but having an "Object reference not set to an instance of an object" on the directcast to the label....
I'm trying to get information from a access database and change the text of the labels.
I'm getting the information, but having an "Object reference not set to an instance of an object" on the directcast to the label....
VB.NET:
Dim ShiftCnt as Integer
Dim TimeCnt as Integer
Dim StartDBTemp as String
Dim Data as String
Dim Location as String
CmdSetupDB = New OleDbCommand ("SELECT * FROM ShiftSetup", ConSetupDB)
ConSetupDB.Open()
DRSetupDB = CmdSetupDB.ExecuteReader
If Not DRSetupDB.Read then
Else
For ShiftCnt = 1 to 3
For TimeCnt = 1 to 8
StartDBTemp = "Shift" & ShiftCnt & "Time" & TimeCnt & "Start"
Data = DrSetupDB(StartDBTemp)
Location = "Shift" & ShiftCnt & "Time" & TimeCnt & "Label"
DirectCast(Me.Controls(Location), Label).Text = Data
Next
Next
End If
End Sub
Last edited: