Solved

Overflowexception

Posted on 2009-07-16
5
461 Views
Last Modified: 2012-05-07
Hi expert,

While excuting one of mysql query, I come across the
overflowexception.

Attached is my code
Could you help?
Thks,
JT
string sqlDialCodes = "select distinct dialcode from carrier_current_rate " + " where  dialcode like '" + countryCodeId + "%'";

            MySqlCommand cmdDialCodes = new MySqlCommand(sqlDialCodes, connection);

            MySqlDataReader rdDialCodes = cmdDialCodes.ExecuteReader();

 

            //int countryCodeId = 0;

 

            while (rdDialCodes.Read())

            {

                lstDialCodeCountry.Items.Add(new ListItem(rdDialCodes.GetInt32(0).ToString()));

                //lstDialCodeCountry.Items.Add(rdDialCodes.GetInt32(0).ToString());

            }

 

            rdDialCodes.Close();

            connection.Close();

Open in new window

0
Comment
Question by:jtran007
  • 2
  • 2
5 Comments
 

Author Comment

by:jtran007
ID: 24873042
Continued ...

System.OverflowException was unhandled by user code
  Message="Value was either too large or too small for an Int32."
  Source="mscorlib"
  StackTrace:
       at System.Convert.ToInt32(Int64 value)
       at System.Int64.System.IConvertible.ToInt32(IFormatProvider provider)
       at MySql.Data.MySqlClient.MySqlDataReader.GetInt32(Int32 i)
       at WebApplication1.carriercode.lstCountry_SelectedIndexChanged(Object sender, EventArgs e) in C:\Develop\Date\June16\MyReport\carriercode.aspx.cs:line 378
       at System.Web.UI.WebControls.ListControl.OnSelectedIndexChanged(EventArgs e)
       at System.Web.UI.WebControls.ListBox.RaisePostDataChangedEvent()
       at System.Web.UI.WebControls.ListBox.System.Web.UI.IPostBackDataHandler.RaisePostDataChangedEvent()
       at System.Web.UI.Page.RaiseChangedEvents()
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
  InnerException:
0
 
LVL 59

Expert Comment

by:Kevin Cross
ID: 24873152
Are there any values of that column that would indeed be invalid, if you say run query directly in query browser?

Additionally, why retrieve as integer and then convert to string?  Why not just pull as string here and probably avoid the issue then you will most likely see the offending string value in your list.

rdDialCodes.GetString(0);
0
 

Accepted Solution

by:
jtran007 earned 0 total points
ID: 24889032
Hi expert,

It is working now: i changed  ..Int32(0)  to Int64(0).

Thanks,
JT
0
 
LVL 59

Expert Comment

by:Kevin Cross
ID: 24895347
Glad you found the issue and thanks for posting to help future readers think of one possible cause of their own issue.

Regards,
Kevin
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Windows Service with UDP 2 28
C# Update Status Bar.... 1 24
install app on other machine 13 18
SQL inner join confusion 15 22
Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now