索引(从零开始)必须大于或等于零,且小于参数列表的大小。
说明: 执行当前 Web 请求期间,出现未经处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.FormatException: 索引(从零开始)必须大于或等于零,且小于参数列表的大小。
源错误:
执行当前 Web 请求期间生成了未经处理的异常。可以使用下面的异常堆栈跟踪信息确定有关异常原因和发生位置的信息。
堆栈跟踪:
[FormatException: 索引(从零开始)必须大于或等于零,且小于参数列表的大小。] System.Text.StringBuilder.AppendFormatHelper(IFormatProvider provider, String format, ParamsArray args) +12941137 System.String.FormatHelper(IFormatProvider provider, String format, ParamsArray args) +63 System.String.Format(IFormatProvider provider, String format, Object[] args) +79 System.Web.UI.WebControls.ChangePassword.AttemptChangePassword() +536 System.Web.UI.WebControls.ChangePassword.OnBubbleEvent(Object source, EventArgs e) +93 System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37 System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e) +120 System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +272 System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +12 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +15 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +35 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1696
下面是我的changePassword.aspx.vb文件中的代码
Dim strconn As String = "Data Source=LAPTOP-1C8DHJ50\SQLEXPRESS;Integrated Security=True;initial catalog=aspnetdb" '建立一个连接字符串strconn
Dim strsql As String = "select * from account_student" '建立一个查询字符串strsql
Dim myconnect As SqlConnection = New SqlConnection(strconn) '建立一个数据连接myconnect
Dim dr As SqlDataReader = Nothing '定义一个sqlDataReader对象
Dim mystr(2) As String
'获取用户输入的用户名,密码和新密码
Dim userName = ChangePassword1.UserName
Dim password = ChangePassword1.CurrentPassword
Dim newPassword = ChangePassword1.NewPassword
Try
Dim update As String = "update account_student set password='" + newPassword + "'where password='" + password + "'"
Dim upcmd As SqlCommand = New SqlCommand(update, myconnect)
myconnect.Open() '打开连接
dr = upcmd.ExecuteReader()
While dr.Read '循环读取数据匹配用户名和密码
dr.GetValues(mystr)
If Equals(userName, mystr(0)) And Equals(password, mystr(1)) Then
'TextBox1.Text = mystr(0) '测试是否能成功读取数据库数据
upcmd.ExecuteNonQuery()
End If
End While
Catch ex As Exception
myconnect.Close() '关闭连接
End Try
说明: 执行当前 Web 请求期间,出现未经处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.FormatException: 索引(从零开始)必须大于或等于零,且小于参数列表的大小。
源错误:
执行当前 Web 请求期间生成了未经处理的异常。可以使用下面的异常堆栈跟踪信息确定有关异常原因和发生位置的信息。
堆栈跟踪:
[FormatException: 索引(从零开始)必须大于或等于零,且小于参数列表的大小。] System.Text.StringBuilder.AppendFormatHelper(IFormatProvider provider, String format, ParamsArray args) +12941137 System.String.FormatHelper(IFormatProvider provider, String format, ParamsArray args) +63 System.String.Format(IFormatProvider provider, String format, Object[] args) +79 System.Web.UI.WebControls.ChangePassword.AttemptChangePassword() +536 System.Web.UI.WebControls.ChangePassword.OnBubbleEvent(Object source, EventArgs e) +93 System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37 System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e) +120 System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +272 System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +12 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +15 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +35 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1696
下面是我的changePassword.aspx.vb文件中的代码
Dim strconn As String = "Data Source=LAPTOP-1C8DHJ50\SQLEXPRESS;Integrated Security=True;initial catalog=aspnetdb" '建立一个连接字符串strconn
Dim strsql As String = "select * from account_student" '建立一个查询字符串strsql
Dim myconnect As SqlConnection = New SqlConnection(strconn) '建立一个数据连接myconnect
Dim dr As SqlDataReader = Nothing '定义一个sqlDataReader对象
Dim mystr(2) As String
'获取用户输入的用户名,密码和新密码
Dim userName = ChangePassword1.UserName
Dim password = ChangePassword1.CurrentPassword
Dim newPassword = ChangePassword1.NewPassword
Try
Dim update As String = "update account_student set password='" + newPassword + "'where password='" + password + "'"
Dim upcmd As SqlCommand = New SqlCommand(update, myconnect)
myconnect.Open() '打开连接
dr = upcmd.ExecuteReader()
While dr.Read '循环读取数据匹配用户名和密码
dr.GetValues(mystr)
If Equals(userName, mystr(0)) And Equals(password, mystr(1)) Then
'TextBox1.Text = mystr(0) '测试是否能成功读取数据库数据
upcmd.ExecuteNonQuery()
End If
End While
Catch ex As Exception
myconnect.Close() '关闭连接
End Try