Scenerio.

I am extracting Primary key from Listbox to read against the Products Table in Northwind database to populate the textbox controls. This particular column "UnitPrice" is giving me this error message:- " Cast from string "Display" to type "Interger" is not valid". Can someone point me to the right direction please. :cheesy: Thanks.

Here is the script.

Private Sub formshow()
'display product info on screen

'create command objects
Dim oCmd As New SqlClient.SqlCommand()
Dim oDR As SqlClient.SqlDataReader
Dim oItem As New clsListItems()

'create string variable
Dim strSql As String
Dim strConn As String

strConn = FbuildAdoConnection()

'get primarykey from listbox
oItem = CType(ListBox1.SelectedItem, clsListItems)

'create sql string
strSql &= "SELECT ProductId, ProductName, QuantityPerUnit, UnitPrice "
strSql &= "UnitsInStock, UnitsOnOrder, ReOrderLevel, Discontinued "
strSql &= "FROM Products "
strSql &= "WHERE ProductId = " & oItem.ProdId

Try
With oCmd
.Connection = New SqlConnection(strConn)
.Connection.Open()
.CommandText = strSql
oDR = .ExecuteReader
End With

'read return dataset to fill screen
If oDR.Read Then
With oDR
txtProductId.Text = .Item("ProductId").ToString()
txtProductName.Text = .Item("Productname").ToString()
txtQtyPerUnit.Text = .Item("QuantityPerUnit").ToString()
txtRorderLevel.Text = .Item("ReOrderLevel").ToString()
txtUnitInStock.Text = .Item("UnitsInStock").ToString()
txtUnitOnOrder.Text = .Item("UnitsOnOrder").ToString()
txtUnitPrice.Text = .Item("UnitPrice").ToString()
txtDisContinued.Text = (CType(.Item("Discontinued"), Boolean))
End With
End If

oDR.Close()
oCmd.Connection.Close()

Catch ex As Exception
MessageBox.Show(ex.Message, "Error", "Display")

End Try

End Sub

Hi,

Change to :

MessageBox.Show(ex.Message, "Error")

Loren Soth

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.