943,748 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Unsolved
  • Views: 3956
  • VB.NET RSS
Mar 30th, 2006
0

Cast from string "Display" to type "Interger" is not valid

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
LennieKuah is offline Offline
47 posts
since Mar 2006
Mar 31st, 2006
0

Re: Cast from string "Display" to type "Interger" is not valid

Hi,

Change to :

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

Loren Soth
Reputation Points: 28
Solved Threads: 4
Posting Whiz in Training
Lord Soth is offline Offline
233 posts
since Mar 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: AD Password Reset Code
Next Thread in VB.NET Forum Timeline: Problem with upgrading Frame 1.1





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC