Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Combo box index change with Access DB

I am trying to update my form based on the selected index from my combo box but am getting errors. I suspect that I have to convert some data but am not able to get around it. Here is my error/code:

Error:
An unhandled exception of type 'System.InvalidCastException' occurred in system.data.dll

Additional information: Object must implement IConvertible.

Code:
Private Sub cbProdName_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbProdName.SelectedIndexChanged
'displays product info based on the item selected

If cbProdName.SelectedIndex <> -1 Then

'clear ProdInfo data set
dsProdInfoObj.Clear()

'look up data based on combo box selection
daProdInfo.SelectCommand.Parameters("ProductID").Value = cbProdName.SelectedValue

'fill the data set
daProdInfo.Fill(dsProdInfoObj)

'convert data
'txtProdID.Text = CInt(txtProdID.Text)
'txtUnitPrice.Text = CDec(txtUnitPrice.Text)
'txtUnitStock.Text = CInt(txtUnitStock.Text)

End If
End Sub

With these lines:
'convert data
txtProdID.Text = CInt(txtProdID.Text)
txtUnitPrice.Text = CDec(txtUnitPrice.Text)
txtUnitStock.Text = CInt(txtUnitStock.Text)

I get this error:

An unhandled exception of type 'System.InvalidCastException' occurred in system.data.dll

Additional information: Object must implement IConvertible.
[1727 byte] By [CB77] at [2007-11-11 8:09:08]
# 1 Re: Combo box index change with Access DB
What is the text in the textboxes when the error occurs? What are you trying to accomplish by converting the .Text properties to numeric values, then back to strings?
Phil Weber at 2007-11-11 21:47:57 >
# 2 Re: Combo box index change with Access DB
the text is blank, I am trying to fill them based on what I select in the combo box.
CB77 at 2007-11-11 21:48:58 >
# 3 Re: Combo box index change with Access DB
If the text is blank, then CInt(txtProdID.Text) will not work. Maybe you intend to do something like this:

With dsProdInfoObj.Tables(0)
txtProdID.Text = .Columns("ProdID")
txtUnitPrice.Text = .Columns("UnitPrice")
txtUnitStock.Text = .Columns("UnitStock")
End With
Phil Weber at 2007-11-11 21:49:56 >
# 4 Re: Combo box index change with Access DB
I have already bound the text boxes to the database though, the dataset should just fill and then set the boxes but I keep getting errors with it.
CB77 at 2007-11-11 21:50:56 >
# 5 Re: Combo box index change with Access DB
it is my second data adapter that isn't filling anything.
CB77 at 2007-11-11 21:52:01 >
# 6 Re: Combo box index change with Access DB
See if any of these help:
http://groups.google.com/groups?q=Object%20must%20implement%20IConvertible
Phil Weber at 2007-11-11 21:53:00 >