ASP.NET代码问题,指定的参数已超出有效值的范围。参数名: index
代码如下:ProtectedSubDetailsView1_ItemUpdating(ByValsenderAsObject,ByValeAsSystem.Web.UI....
代码如下:
Protected Sub DetailsView1_ItemUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewUpdateEventArgs)
Dim txtbox As TextBox = (DetailsView1.Rows(0).Cells(1).Controls(0))
Dim 教师编号 As String = txtbox.Text.Trim()
txtbox = (DetailsView1.Rows(1).Cells(1).Controls(0))
Dim 教师姓名 As String = txtbox.Text.Trim()
txtbox = (DetailsView1.Rows(2).Cells(1).Controls(0))
Dim 系部 As String = txtbox.Text.Trim()
txtbox = (DetailsView1.Rows(3).Cells(1).Controls(0))
Dim 职称 As String = txtbox.Text.Trim()
txtbox = (DetailsView1.Rows(4).Cells(1).Controls(0))
Dim 联系方式 As String = txtbox.Text.Trim()
Dim conn As SqlClient.SqlConnection
conn = New SqlClient.SqlConnection("server=WIN-OBR0R3P88AI\SQLEXPRESS;integrated security=true;user id=sa;password=qwer1234__;database=StuInManDB")
conn.Open()
Dim cmdstr As String = "update 教师信息 set 教师编号='" + 教师编号 + "',教师姓名='" + 教师姓名 + "',系部='" + 系部 + "',职称='" + 职称 + "',联系方式='" + 联系方式 + "'where 教师编号='" + DetailsView1.DataKey.Value.ToString().Trim() + "'"
Dim cmd As SqlClient.SqlCommand
cmd = New SqlClient.SqlCommand(cmdstr, conn)
If cmd.ExecuteNonQuery() Then
Label1.Text = "修改成功"
Else
Label1.Text = "修改操作失败"
End If
conn.Close()
DetailsView1.ChangeMode(DetailsViewMode.ReadOnly)
bind(TextBox1.Text.Trim())
End Sub
提示 :
指定的参数已超出有效值的范围。
参数名: index
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.ArgumentOutOfRangeException: 指定的参数已超出有效值的范围。
参数名: index
源错误:
行 39:
行 40: Protected Sub DetailsView1_ItemUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewUpdateEventArgs)
行 41: Dim txtbox As TextBox = (DetailsView1.Rows(0).Cells(1).Controls(0))!!!!!!!!这句报错
行 42: Dim 教师编号 As String = txtbox.Text.Trim()
行 43: txtbox = (DetailsView1.Rows(1).Cells(1).Controls(0)) 展开
Protected Sub DetailsView1_ItemUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewUpdateEventArgs)
Dim txtbox As TextBox = (DetailsView1.Rows(0).Cells(1).Controls(0))
Dim 教师编号 As String = txtbox.Text.Trim()
txtbox = (DetailsView1.Rows(1).Cells(1).Controls(0))
Dim 教师姓名 As String = txtbox.Text.Trim()
txtbox = (DetailsView1.Rows(2).Cells(1).Controls(0))
Dim 系部 As String = txtbox.Text.Trim()
txtbox = (DetailsView1.Rows(3).Cells(1).Controls(0))
Dim 职称 As String = txtbox.Text.Trim()
txtbox = (DetailsView1.Rows(4).Cells(1).Controls(0))
Dim 联系方式 As String = txtbox.Text.Trim()
Dim conn As SqlClient.SqlConnection
conn = New SqlClient.SqlConnection("server=WIN-OBR0R3P88AI\SQLEXPRESS;integrated security=true;user id=sa;password=qwer1234__;database=StuInManDB")
conn.Open()
Dim cmdstr As String = "update 教师信息 set 教师编号='" + 教师编号 + "',教师姓名='" + 教师姓名 + "',系部='" + 系部 + "',职称='" + 职称 + "',联系方式='" + 联系方式 + "'where 教师编号='" + DetailsView1.DataKey.Value.ToString().Trim() + "'"
Dim cmd As SqlClient.SqlCommand
cmd = New SqlClient.SqlCommand(cmdstr, conn)
If cmd.ExecuteNonQuery() Then
Label1.Text = "修改成功"
Else
Label1.Text = "修改操作失败"
End If
conn.Close()
DetailsView1.ChangeMode(DetailsViewMode.ReadOnly)
bind(TextBox1.Text.Trim())
End Sub
提示 :
指定的参数已超出有效值的范围。
参数名: index
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.ArgumentOutOfRangeException: 指定的参数已超出有效值的范围。
参数名: index
源错误:
行 39:
行 40: Protected Sub DetailsView1_ItemUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewUpdateEventArgs)
行 41: Dim txtbox As TextBox = (DetailsView1.Rows(0).Cells(1).Controls(0))!!!!!!!!这句报错
行 42: Dim 教师编号 As String = txtbox.Text.Trim()
行 43: txtbox = (DetailsView1.Rows(1).Cells(1).Controls(0)) 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询