System.ArgumentOutOfRangeException: Index and length must refer to a location within the string.

Posted by Parthibansk under ASP.NET on 3/23/2013 | Points: 10 | Views : 5199 | Status : [Member] | Replies : 6
when i fill a registration form.. i get this error..

System.ArgumentOutOfRangeException: Index and length must refer to a location within the string.
Parameter name: length


if (dealwith.Substring(0, 1).ToString() == "|")
dealwith = dealwith.Substring(1, dealwith.Length - 1);




Responses

Posted by: Jayakumars on: 3/23/2013 [Member] [MVP] Bronze | Points: 25

Up
0
Down
hi

may i know dealwith value becos this is no have "|" this can u post your code


if (dealwith.Substring(0, 1).ToString() == "|")
dealwith = dealwith.Substring(1, dealwith.Length - 1);



Mark as Answer if its helpful to you

Parthibansk, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Parthibansk on: 3/23/2013 [Member] Starter | Points: 25

Up
0
Down
string dealwith = "";
string sqlstr;
if (Advertising.Checked == true)
dealwith = Advertising.Text.ToString().Trim();
if (Agent.Checked == true)
dealwith = dealwith + "|" + Agent.Text.ToString().Trim();
if (Association.Checked == true)
dealwith = dealwith + "|" + Association.Text.ToString().Trim();
if (Banker.Checked == true)
dealwith = dealwith + "|" + Banker.Text.ToString().Trim();
if (Broker.Checked == true)
dealwith = dealwith + "|" + Broker.Text.ToString().Trim();
if (Buyer.Checked == true)
dealwith = dealwith + "|" + Buyer.Text.ToString().Trim();
if (Distributor.Checked == true)
dealwith = dealwith + "|" + Distributor.Text.ToString().Trim();
if (EnvironmentalServicesandProducts.Checked == true)
dealwith = dealwith + "|" + EnvironmentalServicesandProducts.Text.ToString().Trim();
if (EventManagementCompany.Checked == true)
dealwith = dealwith + "|" + EventManagementCompany.Text.ToString().Trim();
if (Exporter.Checked == true)
dealwith = dealwith + "|" + Exporter.Text.ToString().Trim();
if (Fabricator.Checked == true)
dealwith = dealwith + "|" + Fabricator.Text.ToString().Trim();
if (Financier.Checked == true)
dealwith = dealwith + "|" + Financier.Text.ToString().Trim();
if (GovernmentService.Checked == true)
dealwith = dealwith + "|" + GovernmentService.Text.ToString().Trim();
if (Hospitality.Checked == true)
dealwith = dealwith + "|" + Hospitality.Text.ToString().Trim();
if (HRManagement.Checked == true)
dealwith = dealwith + "|" + HRManagement.Text.ToString().Trim();
if (Importer.Checked == true)
dealwith = dealwith + "|" + Importer.Text.ToString().Trim();
if (Manufacturer.Checked == true)
dealwith = dealwith + "|" + Manufacturer.Text.ToString().Trim();
if (Media.Checked == true)
dealwith = dealwith + "|" + Media.Text.ToString().Trim();
if (NewsandMedia.Checked == true)
dealwith = dealwith + "|" + NewsandMedia.Text.ToString().Trim();
if (PRAgency.Checked == true)
dealwith = dealwith + "|" + PRAgency.Text.ToString().Trim();
if (PrintingIndustry.Checked == true)
dealwith = dealwith + "|" + PrintingIndustry.Text.ToString().Trim();
if (Professional.Checked == true)
dealwith = dealwith + "|" + Professional.Text.ToString().Trim();
if (Retailer.Checked == true)
dealwith = dealwith + "|" + Retailer.Text.ToString().Trim();
if (ServiceProvider.Checked == true)
dealwith = dealwith + "|" + ServiceProvider.Text.ToString().Trim();
if (SoftwareProvider.Checked == true)
dealwith = dealwith + "|" + SoftwareProvider.Text.ToString().Trim();
if (Student.Checked == true)
dealwith = dealwith + "|" + Student.Text.ToString().Trim();
if (SurfaceTreatment.Checked == true)
dealwith = dealwith + "|" + SurfaceTreatment.Text.ToString().Trim();
if (TaxConsultant.Checked == true)
dealwith = dealwith + "|" + TaxConsultant.Text.ToString().Trim();
if (TradeConsultant.Checked == true)
dealwith = dealwith + "|" + TradeConsultant.Text.ToString().Trim();
if (TradingCompany.Checked == true)
dealwith = dealwith + "|" + TradingCompany.Text.ToString().Trim();
if (TransportationShipping.Checked == true)
dealwith = dealwith + "|" + TransportationShipping.Text.ToString().Trim();
if (TravelRelatedServices.Checked == true)
dealwith = dealwith + "|" + TravelRelatedServices.Text.ToString().Trim();
if (Wholesaler.Checked == true)
dealwith = dealwith + "|" + Wholesaler.Text.ToString().Trim();
if (Scrap.Checked == true)
dealwith = dealwith + "|" + Scrap.Text.ToString().Trim();
if (txtothers.Text != "")
dealwith = dealwith + "|others," + txtothers.Text.ToString().Trim();


if (dealwith.Substring(0, 1).ToString() == "|")
dealwith = dealwith.Substring(1, dealwith.Length - 1);


Parthibansk, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jayakumars on: 3/23/2013 [Member] [MVP] Bronze | Points: 25

Up
0
Down
hi

if (Advertising.Checked == true)

check box post client side for this design

otherwise which string stored? this variable dealwith


post them i will solve this.




Mark as Answer if its helpful to you

Parthibansk, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Parthibansk on: 3/23/2013 [Member] Starter | Points: 25

Up
0
Down
dealwith is a column with varchar datatype..

dealwith varchar(2000)

Parthibansk, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jayakumars on: 3/23/2013 [Member] [MVP] Bronze | Points: 25

Up
0
Down
hi
can u give teamviewer id or may i know which word stroed this variable

i m asking like this

ex:
dealwith="AspDotnetCode"


Mark as Answer if its helpful to you

Parthibansk, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Parthibansk on: 3/23/2013 [Member] Starter | Points: 25

Up
0
Down
i fixed it.. thanks..

Parthibansk, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response