问题描述
ServerErrorin'/'Application.Indexwasoutsidetheboundsofthearray.Description:Anunhandledexceptionoccurredduringtheexecutionofthecurrentwebrequest.Pleasereviewthestacktraceformoreinformationabouttheerrorandwhereitoriginatedinthecode.ExceptionDetails:System.IndexOutOfRangeException:Indexwasoutsidetheboundsofthearray.SourceError:Line78:parameters[2].Value=model.state;Line79:parameters[3].Value=model.CreateTime;Line80:parameters[4].Value=model.Remarks;Line81:Line82:intobj=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);SourceFile:F:2222移民留学DALRollImage.csLine:80StackTrace:[IndexOutOfRangeException:Indexwasoutsidetheboundsofthearray.]HL.DAL.RollImage.Add(RollImagemodel)inF:2222移民留学DALRollImage.cs:80HL.BLL.RollImage.Add(RollImagemodel)inF:2222移民留学BLLRollImage.cs:55HL.Web.Module.RollImage.RollImageadd.btnSave_Click(Objectsender,EventArgse)inF:2222移民留学WebModuleRollImageRollImageadd.aspx.cs:74System.Web.UI.WebControls.Button.OnClick(EventArgse)+118System.Web.UI.WebControls.Button.RaisePostBackEvent(StringeventArgument)+112System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(StringeventArgument)+10System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandlersourceControl,StringeventArgument)+13System.Web.UI.Page.RaisePostBackEvent(NameValueCollectionpostData)+36System.Web.UI.Page.ProcessRequestMain(BooleanincludeStagesBeforeAsyncPoint,BooleanincludeStagesAfterAsyncPoint)+5563VersionInformation:Microsoft.NETFrameworkVersion:4.0.30319;ASP.NETVersion:4.0.30319.1
解决方案
解决方案二:
明显是数组越界了.调试下代码吧
解决方案三:
80行parameters[4],你定义的时候压根没有5个元素,所以访问不到4下标
解决方案四:
引用2楼xdashewan的回复:
80行parameters[4],你定义的时候压根没有5个元素,所以访问不到4下标
我删了一个,这应该不影响吧
解决方案五:
引用1楼peng2739956的回复:
明显是数组越界了.调试下代码吧
那怎样解决呀
解决方案六:
引用3楼huangwumao1的回复:
我删了一个,这应该不影响吧
检查数组定义,长度为5,下标最大只能是4,下标的最大值只能是:数组长度-1。你要么删除parameters[4].Value=model.Remarks;这句,要么定义的时候把数组长度+1