Link to home
Start Free TrialLog in
Avatar of jtran007
jtran007

asked on

Overflowexception

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

Avatar of jtran007
jtran007

ASKER

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:
Avatar of Kevin Cross
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);
ASKER CERTIFIED SOLUTION
Avatar of jtran007
jtran007

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Glad you found the issue and thanks for posting to help future readers think of one possible cause of their own issue.

Regards,
Kevin