trying to find source of error

B

Bruce D

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
 
J

jongalloway

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
 
B

Bruce D

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
 
J

jongalloway

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top