Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB.NET 1.0 > VB.NET 2002/2003 Basics
|
VB.NET 2002/2003 Basics For coders who are new to Visual Basic, working in .NET versions 2002 or 2003 (1.0 and 1.1).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET 2002/2003 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 30th, 2005, 12:28 PM
h3x h3x is offline
Registered User
 
Join Date: Jan 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Im getting this error in my web page

hi there i just started .NET (ASP n VB) this semester n i created this webpage which brings back data from the database ... whn i enter the search parameter it gives me this error .. "Cast from string "" to type 'Integer' is not valid."
heres my code ...plz help me out ...

LookUpInventoryByStockNumber.aspx.vb

Private Sub btnSearchInvt_click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearchInvt.Click

        Try
            Dim InventoryInformation As DataSet = Lab1.OrderSystem.LookUpInventoryByStockNumber(txtE mpID2.Text, StockNum.Text)
            If InventoryInformation.Tables("InventoryInformation" ).Rows.Count > 0 Then
                With InventoryInformation.Tables("InventoryInformation" ).Rows(0)
                    StockNum.Text = .Item("StockNumber")
                    InventoryNumber.Text = .Item("InventoryNumber")
                    Description.Text = .Item("Description")
                    Price.Text = .Item("Price")
                    ReOrderLevel.Text = .Item("ReOrderLevel")
                    UnitCost.Text = .Item("UnitCost")
                    OrderUnitSize.Text = .Item("OrderUnitSize")
                    OrderUnitType.Text = .Item("OrderUnitType")
                    Discontinued.Text = .Item("Discontinued")
                    QuantityOnHand.Text = .Item("QuantityOnHand")
                End With
            Else
                lblErrStock.Text = txtEmpID2.Text & " was not found "
            End If
        Catch ex As Exception
            lblErrStock.Text = ex.Message
        End Try
    End Sub

Inventory.vb
Public Class Inventory
    Public Shared Function LookInventoryByStockNumber(ByVal EmployeeID As Integer, ByVal StockNum As Integer) As DataSet
        Dim eVideo As SqlConnection = New SqlConnection(eVideoConnectionString)
        Dim adapter As SqlDataAdapter = New SqlDataAdapter("exec LookUpInventoryByStockNumber @EmployeeID, @StockNum", eVideo)
        adapter.SelectCommand.Parameters.Add("@EmployeeID" , SqlDbType.Int).Value = EmployeeID
        Dim InventoryInformation As DataSet = New DataSet
        adapter.Fill(InventoryInformation, "InventoryInformation")
        Return InventoryInformation
    End Function
End Class


 
Old January 31st, 2005, 10:32 AM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 142
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Your problem is exactly as the error describes. Somewhere in your code you are assigning an empty string to an integer. You need to use an If statement to assign the value, assigning 0 if the string is empty.

Try stepping through your code and seeing where the error occurs. If you need more help, post the exact line you're having problems on.

 
Old January 31st, 2005, 11:55 AM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

To find the line causing the trouble, you can set the value of an integer between each line of code, then assess its value in the Catch.
If the value in the Catch is 5, the line before it was set to 5 ran, the one after it was set to 5 didn't.





Similar Threads
Thread Thread Starter Forum Replies Last Post
how to prevent a web page/window page from copying pradeeppatnaik81 C# 2 April 9th, 2008 03:36 AM
How to diplay web page inside another web page win cyberjoe C# 2 March 1st, 2007 05:35 AM
im new with c# i need help tunisiano C# 7 February 17th, 2007 04:54 AM
Cookie Error when run web page test.aspx C#.net minhpx General .NET 1 August 10th, 2004 01:23 AM
refreshing a page...simple im sure but i cant do i ps124 ASP.NET 1.0 and 1.1 Basics 1 March 14th, 2004 10:57 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.