Have successfully filled a combo box using either a collection or listof. However, having trouble with one particular combo box that does not play nice. the code using list of:
When this was used to capture the error:
The message is no value given for one or more required parameters, source is Jet database engine.
I'm at a loss. Any help would be great. Thanks.
Code:
Private Sub LoadProfCbo() 'Load cboProfession
Dim CP As New CProfession
Dim obj As Object
obj = frmFind.lstDisplay.SelectedItem
CP = CType(obj, CProfession)
Me.cboProfession.Items.Clear()
Dim pCol As New Collection
dataMgr.ProfessionLoad(pCol)
For Each CP In pCol
cboProfession.Items.Add(CP)
Next CP
pCol = Nothing
End Sub
Public Function ProfessionLoad(ByRef c As Collection) As Collection
da = New OleDbDataAdapter
Dim dr As DataRow
Dim ds As New DataSet
Dim CP As CProfession
cmd = New OleDbCommand("Select ProfessionID, Profession From Profession", cn)
da.SelectCommand = cmd
da.Fill(ds, "Profession") 'jumps out here and loads the main screen that holds the combo box. no error msg.
Try
For Each dr In ds.Tables("Profession").Rows
CP = New CProfession
CP.Profession = CStr(dr("Profession"))
CP.ProfessionID = CInt(dr("ProfessionID"))
c.Add(CP)
Next
Catch ex As Exception
MsgBox(ex.Message)
End Try
Return c
End Function
When this was used to capture the error:
Code:
Dim myReader As OleDbDataReader
myReader = cmd.ExecuteReader
Do While myReader.Read
CP = New CProfession
CP.ProfessionID = CInt(myReader("ProfessionID").ToString)
CP.Profession = CStr(myReader("Profession"))
lp.Add(CP)
Loop
Return lp
Exit Function
Catch e As OleDbException
Dim errorMessages As String = ""
Dim i As Integer
For i = 0 To e.Errors.Count - 1
errorMessages += "Index #" & i.ToString() & ControlChars.Cr _
& "Message: " & e.Errors(i).Message & ControlChars.Cr _
& "NativeError: " & e.Errors(i).NativeError & ControlChars.Cr _
& "Source: " & e.Errors(i).Source & ControlChars.Cr
Next i
MsgBox(errorMessages)
End Try
I'm at a loss. Any help would be great. Thanks.