473,407 Members | 2,320 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

FormatingException was Handled

Error : Input string was not in a correct format.

Expand|Select|Wrap|Line Numbers
  1. public partial class frmDealerForm : Form
  2.     {
  3.         DataTable t;
  4.         DataRow r;
  5.         string id;
  6.         private void btnNew_Click(object sender, EventArgs e)
  7.         {
  8.             txtdealerID.ResetText();
  9.             txtname.ResetText();
  10.             txtaddress.ResetText();
  11.             txtphoneno.ResetText();
  12.             try
  13.             {
  14.                 int ctr, len;
  15.                 string codeval;
  16.                 t = kalliskaBillingDataSet.Tables["DealerDetail"];
  17.                     len = t.Rows.Count - 1;
  18.                     r = t.Rows[len];
  19.                     id = r["DealerID"].ToString();
  20.                     codeval = id.Substring(1, 3);
  21.         //Input string was not in a correct format                    
  22.         ctr = System.Convert.ToInt32(codeval);                           
  23.                    if ((ctr >= 1) && (ctr < 9))
  24.                     {
  25.                         ctr = ctr + 1;
  26.                         txtdealerID.Text = "DE00" + ctr;
  27.                         txtdealerID.Enabled = false;
  28.                     }
  29.                     else if ((ctr >= 9) && (ctr < 99))
  30.                     {
  31.                         ctr = ctr + 1;
  32.                         txtdealerID.Text = "DE0" + ctr;
  33.                         txtdealerID.Enabled = false;
  34.                     }
  35.                     else if (ctr >= 99)
  36.                     {
  37.                         ctr = ctr + 1;
  38.                         txtdealerID.Text = "DE" + ctr;
  39.                         txtdealerID.Enabled = false;
  40.                     }
  41.                 }
  42.  
  43.             catch (IndexOutOfRangeException)
  44.             {
  45.                 txtdealerID.Text = "DE00";
  46.             }
  47.             btnNew.Enabled = true;
  48.         }
Attached Images
File Type: jpg Dealer1.jpg (29.3 KB, 129 views)
File Type: jpg DealerDetail.jpg (18.6 KB, 116 views)
Oct 26 '12 #1
1 2028
Frinavale
9,735 Expert Mod 8TB
Put a break point on line 22 in the above posted code to determine what your substring is returning. It sounds like it's not returning a number.
Oct 26 '12 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Fred Gravel | last post by:
I have a Windows app that I have installed on 3 client machines (all win2k) thatreturn an un-handled error message when starting up. I have placed 'Try/Catch/Finally' blocks in the 'sub main' and...
2
by: Amos Soma | last post by:
In my Win form, I have KeyPreview set to True. In my form KeyUp method, I have the following code: if (e.KeyCode == Keys.F10) { e.Handled = true; MessageBox.Show( "F10 pressed" ); } The...
5
by: Uchiha Jax | last post by:
I have created a custom textbox which contains an arraylist of permitted chars. Any chars that are not in the list are not permitted. One of the events looks like this and is attached to either...
4
by: Tom | last post by:
I have a ComboBox that I wrote a KeyPress event for. Basically, it looks to make sure that a numeric key has been pressed; if not, then it does a Beep() and sets e.Handled to True. This should, as...
5
by: Lucvdv | last post by:
Can someone explain why this code pops up a messagebox saying the ThreadAbortException wasn't handled? The first exception is reported only in the debug pane, as expected. The second (caused by...
2
by: Murthy | last post by:
Hi, After genarating the exe when i run the exe the following error is comming. Common Language Runtime Debugging Services Application has generated an exception that could not be handled....
2
by: **Developer** | last post by:
I have a usercontrol that contains the following. To my surprise the form containing this control get KeyUp events. Help says that for KeyPress setting e.Handled = True suppresses KeyPress...
4
by: **Developer** | last post by:
I have a usercontrol that contains the following. To my surprise the form containing this control get KeyUp events. Help says that for KeyPress setting e.Handled = True suppresses KeyPress...
2
by: Alex | last post by:
Hello, All. I encouraged some strange behaviour of either IIS, ASP.NET, IE or donn't know what... I have a simple wait.aspx page private void Page_Load(object sender, System.EventArgs e) {...
6
by: mj2736 | last post by:
I created a windows form control that inherits from the standard .Net DataGridView control, to which I've added custom functionality. Instead of using the standard control in my applications, I use...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.