asp.net在修改数据时提示::指定的参数已超出有效值的范围。 参数名: index这个错误
点了修改之后,可以修改东西,但是改完要确认修改的时候,就会提示这个错误。我是自己给GridView控件写的修改,代码protectedvoidGridView1_RowU...
点了修改之后,可以修改东西,但是改完要确认修改的时候,就会提示这个错误。我是自己给GridView控件写的修改,代码
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
string _Type = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString().Trim();
string _Publishtime = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[3].Controls[0])).Text.ToString().Trim();
string _Title = GridView1.DataKeys[e.RowIndex].Value.ToString();
string Update_sql = "UPDATE Eassy_1 SET Type='" + _Type + "',Publishtime='" + _Publishtime + "' WHERE Title='" + _Title + "'";
SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["EassyConnectionString1"].ConnectionString);
try
{
conn.Open();
SqlCommand cmm = new SqlCommand();
cmm.CommandText = Update_sql;
cmm.Connection = conn;
cmm.ExecuteNonQuery();
conn.Close();
}
catch (Exception ex)
{
Response.Write("数据库错误,错误原因:" + ex.Message);
GridView1.EditIndex = -1;
GridView1.DataBind();
}
} 展开
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
string _Type = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString().Trim();
string _Publishtime = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[3].Controls[0])).Text.ToString().Trim();
string _Title = GridView1.DataKeys[e.RowIndex].Value.ToString();
string Update_sql = "UPDATE Eassy_1 SET Type='" + _Type + "',Publishtime='" + _Publishtime + "' WHERE Title='" + _Title + "'";
SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["EassyConnectionString1"].ConnectionString);
try
{
conn.Open();
SqlCommand cmm = new SqlCommand();
cmm.CommandText = Update_sql;
cmm.Connection = conn;
cmm.ExecuteNonQuery();
conn.Close();
}
catch (Exception ex)
{
Response.Write("数据库错误,错误原因:" + ex.Message);
GridView1.EditIndex = -1;
GridView1.DataBind();
}
} 展开
若以下回答无法解决问题,邀请你更新回答
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询