Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Overflowexception

Posted on 2009-07-16
5
Medium Priority
?
481 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 60

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 60

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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this article, I’ll talk about multi-threaded slave statistics printed in MySQL error log file.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

610 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