Click here to Skip to main content
15,748,330 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
please help me i am getting this exception when this will occurs.
StartIndex cannot be less than zero.
Parameter name: startIndex

when debugger comes to this line it is throwing exception
email = email.Remove(email.IndexOf(EmployeeDataset.Tables[0].Rows[j][
"EmailId"].ToString()), Convert.ToInt32(EmployeeDataset.Tables[0].Rows[j]["EmailId"].ToString().Length + 1));

please help me
Updated 8-Jan-12 20:00pm

1 solution

My suspicion is that the .IndexOf method call is returning -1 which indicates that the value was not found.

I would break down your statement for debugging purposes:
int indexOfEmail = email.IndexOf(EmployeeDataset.Tables[0].Rows[j]["EmailId"].ToString());
int lengthOfEmail = EmployeeDataset.Tables[0].Rows[j]["EmailId"].ToString().Length;
if( indexOfEmail >= 0 )
   email = email.Remove(indexOfEmail, lengthOfEmail + 1);

Now run the debugger with a breakpoint set on the int indexOfEmail line and step through each line checking the values as you go. I suspect that you will find indexOfEmail = -1.
Share this answer
Espen Harlinn 4-Jan-12 11:29am    
Good answer :)
Monjurul Habib 4-Jan-12 12:19pm    
RaisKazi 9-Jan-12 2:06am    
My 5.

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