trying to find source of error

Discussion in 'ASP .Net' started by Bruce D, Oct 25, 2004.

  1. Bruce D

    Bruce D Guest

    I'm new to .NET and I have a error that is coming up but it's not telling me
    where the error is coming from (no file). Is that because I'm doing
    something wrong...or is it a type of error that has nothing to do with my
    code? P.S. I'm debugging someone else's code. Here's what the screen looks
    like when I load the page:

    ***************************************************
    Input String was not in a correct format

    Exception Details: System.FormatException: Input string was not in a correct
    format

    Source Error:
    An unhandled exception was generated during the execution of the current web
    request. Information regarding the origin and location of the exception can
    be identified using the exception stack trace below.

    Stack Trace:

    [FormatException: Input string was not in a correct format.]
    System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo
    info) +0
    System.Int32.Parse(String s) +38
    customer.OrderDetail.loadDetail()
    customer.OrderDetail.Page_Load(Object sender, EventArgs e)
    System.Web.UI.Control.OnLoad(EventArgs e) +67
    System.Web.UI.Control.LoadRecursive() +35
    System.Web.UI.Page.ProcessRequestMain() +731
    ***************************************************

    Any help is greatly appreciated.

    -bruce duncan
     
    Bruce D, Oct 25, 2004
    #1
    1. Advertising

  2. Bruce D

    jongalloway Guest

    Bruce -
    You probably have a page called OrderDetail.aspx. There's a matching
    file, either OrderDetail.aspx.vb or OrderDetail.aspx.cs. That page has
    a function called loadDetail that is reading an OrderDetail ID number
    from something, possibly the Query String. It's expecting the value to
    be an integer, but it's getting something it can't convert to an
    integer.

    I'd set a breakpoint on the loadDetail function and run the application
    in Debug mode, then step through the loadDetail function when the
    breakpoint hits and see where it blows up.
    - Jon
    http://weblogs.asp.net/jgalloway
     
    jongalloway, Oct 25, 2004
    #2
    1. Advertising

  3. Bruce D

    Bruce D Guest

    >
    > I'd set a breakpoint on the loadDetail function and run the application
    > in Debug mode, then step through the loadDetail function when the
    > breakpoint hits and see where it blows up.
    > - Jon
    > http://weblogs.asp.net/jgalloway


    Jon,
    Thanks for the advice. Since I'm developing this project on a PC other than
    the web server, I can't run it in debug mode (or at least I can't get it to
    work). So, I've been trying to narrow down the possible bugs...here's my
    function...any thoughts?

    private void loadDetail()
    {
    string orderdtlSQL = "select orderqty, ium, partnum, linedesc, unitprice
    from pub.orderdtl where company='OGI' and ordernum = '" + ordernum + "' and
    custnum = " + custnum;
    DataTable table = d.getDataTable("vntg",orderdtlSQL);
    table.Columns.Add("extprice");
    int ShipQty = 0;
    foreach(DataRow row in table.Rows)
    {
    // extprice = qty * unitprice
    row["extprice"] = Single.Parse(row["orderqty"].ToString()) *
    Single.Parse(row["unitprice"].ToString());
    // accumulate qty
    ShipQty += Int32.Parse(row["orderqty"].ToString());
    }
    this.lblQtyTotal.Text = ShipQty.ToString();
    this.rptOrderDetail.DataSource = table;
    this.rptOrderDetail.DataBind();

    }

    Thanks,
    bruce
     
    Bruce D, Oct 26, 2004
    #3
  4. Bruce D

    jongalloway Guest

    Bruce -
    It looks from the stack trace that the error is on this line:
    ShipQty += Int32.Parse(row["orderqty"].ToString());

    You should check your data to see if you have non-numeric data in your
    orderqty field. From your code, this SQL statement would probably find
    it:
    select * from pub.orderdtl where company='OGI' and isnumeric(orderqty)
    = 0;

    Additionally, you could wrap the line that's throwing the exception
    with a try / catch:

    try
    {
    ShipQty += Int32.Parse(row["orderqty"].ToString());
    }
    catch (Exception e)
    {
    Context.Trace.Warn("Exception", "Non-numeric ORDERQTY", e);
    }

    The Context.Trace.Warn statement writes the error info out to the
    ASP.NET trace. If you're not familiar with that, this article is a good
    place to start:
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspnet/html/asp01252001.asp
    - Jon
    http://weblogs.asp.net/jgalloway
     
    jongalloway, Oct 30, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. 28tommy
    Replies:
    4
    Views:
    346
    28tommy
    Dec 25, 2005
  2. mdh

    trying to find the error

    mdh, May 2, 2008, in forum: C Programming
    Replies:
    6
    Views:
    245
    Ian Collins
    May 3, 2008
  3. Wybo Dekker
    Replies:
    1
    Views:
    363
    Yukihiro Matsumoto
    Nov 15, 2005
  4. vdvorkin
    Replies:
    0
    Views:
    412
    vdvorkin
    Feb 10, 2011
  5. vdvorkin
    Replies:
    3
    Views:
    813
    vdvorkin
    Feb 14, 2011
Loading...

Share This Page