Question

I wrote the following queury:

SELECT        ItemName, Price
FROM          ItemInventoryControl
WHERE        (ItemName = @ItemName)

Now, I am trying the retrieve the Price with the following procedure:

Dim StrItemName As String = btnItemButton.Text
Dim strQty As String = "1"
Dim dblQty As Double = CDbl(strQty)

Dim table As DataTable = ItemInventoryControlPriceTableAdapter.GetData(StrItemName)
Dim dblPrice As Double = table.Rows(0).Field(Of Double)("Price") **'Error here**
Dim dblTotal As Double = dblPrice * dblQty

MessageBox.Show(dblPrice.ToString)

However, I am getting the following error: Make sure the source type is convertible to the destination type.

I am using SQLCE, and the Price field is set to Floatdata type. So I do not understand why I am getting a conversion error when I am trying to retrieve as a Double.

Any help will be appreciated.

Was it helpful?

Solution

Your call throws an error because you are not retrieving a Double. It is strongly typed remember.

The laziest solution is to replace the line with the error with something like this:

Dim dblPrice as Double = table.rows(0)("Price")

which will actually work.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top