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
Solved

Overflowexception

Posted on 2009-07-16
5
470 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

839 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