GridView编辑操作在点更新时出现错误
GridView编辑操作在点更新时出现错误用户代码未处理 ArgumentOutOfRangeException
指定的参数已走出有效值的范围。
参数名:index
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
string sqlstr = "update Vehicles set licence='"
+ ((TextBox)(GridView1.Rows[e.RowIndex].Cells[3].Controls[0])).Text.Trim().ToString() + "',vehicle_type='"
+ ((TextBox)(GridView1.Rows[e.RowIndex].Cells[4].Controls[0])).Text.Trim().ToString() + "',vehicle_brand='"
+ ((TextBox)(GridView1.Rows[e.RowIndex].Cells[5].Controls[0])).Text.Trim().ToString() + "',Purchase_date='"
+ ((TextBox)(GridView1.Rows[e.RowIndex].Cells[6].Controls[0])).Text.Trim().ToString() + "',Purchase_price="
+ ((TextBox)(GridView1.Rows[e.RowIndex].Cells[7].Controls[0])).Text.Trim().ToString() + ",Initial_km='"
+ ((TextBox)(GridView1.Rows[e.RowIndex].Cells[8].Controls[0])).Text.Trim().ToString() + "',Engine_num='"
+ ((TextBox)(GridView1.Rows[e.RowIndex].Cells[9].Controls[0])).Text.Trim().ToString() + "',Frame_num='"
+ ((TextBox)(GridView1.Rows[e.RowIndex].Cells[10].Controls[0])).Text.Trim().ToString() + "',Purchase_tax_num='"
+ ((TextBox)(GridView1.Rows[e.RowIndex].Cells[11].Controls[0])).Text.Trim().ToString() + "',Theory_fuel_consumption='"
+ ((TextBox)(GridView1.Rows[e.RowIndex].Cells[12].Controls[0])).Text.Trim().ToString() + "',Train_licence='"
+ ((TextBox)(GridView1.Rows[e.RowIndex].Cells[13].Controls[0])).Text.Trim().ToString() + "',Branch='"
+ ((TextBox)(GridView1.Rows[e.RowIndex].Cells[14].Controls[0])).Text.Trim().ToString() + "',Train_id='"
+ ((TextBox)(GridView1.Rows[e.RowIndex].Cells[15].Controls[0])).Text.Trim().ToString() + "',Current_status='"
+ ((TextBox)(GridView1.Rows[e.RowIndex].Cells[17].Controls[0])).Text.Trim().ToString() + "',Out_date='"
+ ((TextBox)(GridView1.Rows[e.RowIndex].Cells[18].Controls[0])).Text.Trim().ToString() + "',vehicle_note='"
+ ((TextBox)(GridView1.Rows[e.RowIndex].Cells[19].Controls[0])).Text.Trim().ToString() + "'where Registration_id='"
+ GridView1.DataKeys[e.RowIndex].Value.ToString()+ "'";
try
{
if (sqlcon.State.ToString() == "Closed") sqlcon.Open();
SqlCommand sqlcom = new SqlCommand(sqlstr, sqlcon);
sqlcom.ExecuteNonQuery();
sqlcon.Dispose();
if (sqlcon.State.ToString() == "Open") sqlcon.Close();
GridView1.EditIndex = -1;
//GridViewBind();
}
catch (Exception ex)
{
Response.Write("数据库错误,错误原因:" + ex.Message);
Response.End();
}
}