Click here to Skip to main content
15,885,244 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
if (a == string.Empty)
           {

               NO = "EN0001";

           }
           else
           {
               int i = Convert.ToInt32(a.Substring(2, 4));
               i += 1;
               no = i;
               NO = "EN" + a.Substring(2, 4 - i.ToString().Length) + i;

           }
           return NO;


ia have error that"
SQL
Index and length must refer to a location within the string.
Parameter name: length

" please any one can help me please,
Posted

1 solution

You need to check the length of the string in a before you start using Substring: if it only has three characters for example, you code will fail with the error you are getting.
try this:
C#
if (a == string.Empty)
Becomes
C#
if (string.IsNullOrWhiteSpace(a) || a.Length < 6)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900