| | |
Cast from string "Display" to type "Interger" is not valid
Please support our VB.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Mar 2006
Posts: 26
Reputation:
Solved Threads: 0
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
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
- google "keyword" question (Search Engine Optimization)
- Deitel's "C++ How To Program" exercise 2.18 (C++)
- Back button brings "cannot display ... " certain sites (Windows NT / 2000 / XP)
- This ought to be simple - extra spaces (PHP)
Other Threads in the VB.NET Forum
- Previous Thread: AD Password Reset Code
- Next Thread: Problem with upgrading Frame 1.1
| Thread Tools | Search this Thread |
.net .net2005 30minutes 2005 2008 access account arithmetic array basic binary bing button buttons c# center check code combobox component connectionstring convert crystalreport data database databasesearch datagrid datagridview design dissertation dissertations dissertationthesis dropdownlist excel file-dialog folder ftp generatetags google gridview hardcopy image images inline insert intel internet listview mobile monitor ms net networking output passingparameters peertopeervideostreaming picturebox picturebox1 plugin port print printing problem problemwithinstallation project reports" save savedialog searchbox searchvb.net select serial server soap sql table tcp text textbox timer toolbox trim update updown user usercontrol vb vb.net vb.netcode vb.netformclosing()eventpictureboxmessagebox vb2008 vbnet view visual visualbasic visualbasic.net visualstudio visualstudio2008 web wpf





