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

Please support our VB.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Mar 2006
Posts: 26
Reputation: LennieKuah is an unknown quantity at this point 
Solved Threads: 0
LennieKuah LennieKuah is offline Offline
Light Poster

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

 
0
  #1
Mar 30th, 2006
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
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 233
Reputation: Lord Soth is an unknown quantity at this point 
Solved Threads: 4
Lord Soth's Avatar
Lord Soth Lord Soth is offline Offline
Posting Whiz in Training

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

 
0
  #2
Mar 31st, 2006
Hi,

Change to :

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

Loren Soth
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC