如何解决"索引超出了数组界限"?
索引超出了数组界限。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.IndexOutOfRangeException: 索引超出了数组界限。
源错误:
行 37: SqlParameter[] parms = new SqlParameter[]{
行 38: };
行 39: parms[0].Value = account.VipCode;
行 40: parms[1].Value = account.Zjcode;
行 41: parms[2].Value = account.Oldpassword;
源文件: g:\VIP\VIPWebsite\App_Code\DataProvider\EditPwdProvider.cs 行: 39
堆栈跟踪:
[IndexOutOfRangeException: 索引超出了数组界限。]
VIPWebsite.DataProvider.EditPwdProvider.Update(BaseEntity entity) in g:\VIP\VIPWebsite\App_Code\DataProvider\EditPwdProvider.cs:39
VIPWebsite.BussinesLogic.EditPwdManager.UserinfoUpdate(EditpwdEntity account) in g:\VIP\VIPWebsite\App_Code\BussinesLogic\EditPwdManager.cs:38
VIPWebsite.EditPassWord.Updateuserinfo() in g:\VIP\VIPWebsite\EditPassWord.aspx.cs:66
VIPWebsite.EditPassWord.SureButton_Click(Object sender, EventArgs e) in g:\VIP\VIPWebsite\EditPassWord.aspx.cs:99
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +107
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5102
---------------------------------------
EditPwdProvider.cs 代码如下:
using System;
using System.Data;
using System.Data.SqlClient;
using VIPWebsite.Entity;
namespace VIPWebsite.DataProvider
{
/// <summary>
/// Summary description for WebAccountProvider.
/// </summary>
public class EditPwdProvider : BaseDataProvider
{
private const string SQL_USER_update = "Update_userinfo ";
private const string PARM_vip_CODE = "@vipcode ";
private const string PARM_USER_zjcode = "@zjcode ";
private const string PARM_oldpassword = "@oldpassword ";
private const string PARM_newpassword = "@newpassword ";
private const string PARM_repeatpassword = "@repeatpassword ";
public EditPwdProvider()
{
}
#region BaseDataProvider Members
public override bool Update(BaseEntity entity)
{
if (entity.GetType().Equals(typeof(EditpwdEntity)))
{
EditpwdEntity account = entity as EditpwdEntity;
SqlParameter[] parms = new SqlParameter[]{
};
parms[0].Value = account.VipCode;
parms[1].Value = account.Zjcode;
parms[2].Value = account.Oldpassword;
parms[3].Value = account.Newpassword;
parms[4].Value = account.Repeatpassword;
using (SqlConnection conn = new SqlConnection(this.DbConnString))
{
try
{
int iRet = SQLHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, SQL_USER_update, parms);
return (iRet > 0) ? true : false;
}
catch
{
return false;
}
finally
{
if (conn.State.Equals(ConnectionState.Open)) { conn.Close(); }
}
}
}
return false;
}
public override object SelectSingleObject(BaseEntity entity)
{
// TODO: Add WebAccountProvider.GetMultipleRows implementation
throw new NotSupportedException();
}
public override System.Data.DataSet SelectAllRow(BaseEntity entity)
{
// TODO: Add WebAccountProvider.GetMultipleRows implementation
throw new NotSupportedException();
}
public override System.Data.SqlClient.SqlDataReader SelectOneRow(BaseEntity entity)
{
// TODO: Add WebAccountProvider.GetSingleRow implementation
throw new NotSupportedException();
}
public override bool Add(BaseEntity entity)
{
// TODO: Add WebAccountProvider.GetSingleRow implementation
throw new NotSupportedException();
}
public override bool Delete(BaseEntity entity)
{
// TODO: Add WebAccountProvider.Delete implementation
throw new NotSupportedException();
}
#endregion
}
}
---------------------------------------
各位大侠帮忙看看这个问题该如何解决?
[解决办法]
SqlParameter[] parms = new SqlParameter[4];
[解决办法]
应该是5SqlParameter[] parms = new SqlParameter[5];
[解决办法]
确保你的parms里面元素多于3...
之前加个判断是否 <0或者> =Length
[解决办法]
-_-b
LZ你嘴太快了.才看到0回复,进来就两个回复了-_-b
[解决办法]
SqlParameter[] parms = new SqlParameter[]
{new SqlParameter(),new SqlParameter(),new SqlParameter(),new SqlParameter(),new SqlParameter()};