?
Solved

Overflowexception

Posted on 2009-07-16
5
Medium Priority
?
479 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

Percona Live Europe 2017 | Sep 25 - 27, 2017

The Percona Live Open Source Database Conference Europe 2017 is the premier event for the diverse and active European open source database community, as well as businesses that develop and use open source database software.

Question has a verified solution.

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

The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this article, we’ll look at how to deploy ProxySQL.
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 Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

752 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