指定的参数已超出有效值的范围. index 10
publicpartialclass_Default:System.Web.UI.Page{protectedvoidPage_Load(objectsender,Eve...
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
bind();
}
public void bind()
{
SqlConnection connection = new SqlConnection(ConfigurationManager.AppSettings["sqlcon"]);
string str = " select * from 学员 ";
SqlDataAdapter da = new SqlDataAdapter(str, connection);
DataSet ds = new DataSet();
connection.Open();
da.Fill(ds, "学员");
GridView1.DataSource = ds.Tables[0];
GridView1.DataKeyNames = new string[] { "编号" };
GridView1.DataBind();
connection.Close();
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
bind();
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["sqlcon"]);
con.Open();
string sqlstr = "update 学员 set 姓名='" + ((TextBox)(GridView1.Rows[e.RowIndex].Cells[2].Controls[0])).Text.ToString().Trim() + "',身份证号='" + ((TextBox)(GridView1.Rows[e.RowIndex].Cells[4].Controls[0])).Text.ToString().Trim() + "' where 编号='" + GridView1.DataKeys[e.RowIndex].Value.ToString() + "'";
SqlCommand com = new SqlCommand(sqlstr, con);
com.ExecuteNonQuery();
con.Close();
GridView1.EditIndex = -1;
bind();
}
}
这是为什么????? 展开
{
protected void Page_Load(object sender, EventArgs e)
{
bind();
}
public void bind()
{
SqlConnection connection = new SqlConnection(ConfigurationManager.AppSettings["sqlcon"]);
string str = " select * from 学员 ";
SqlDataAdapter da = new SqlDataAdapter(str, connection);
DataSet ds = new DataSet();
connection.Open();
da.Fill(ds, "学员");
GridView1.DataSource = ds.Tables[0];
GridView1.DataKeyNames = new string[] { "编号" };
GridView1.DataBind();
connection.Close();
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
bind();
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["sqlcon"]);
con.Open();
string sqlstr = "update 学员 set 姓名='" + ((TextBox)(GridView1.Rows[e.RowIndex].Cells[2].Controls[0])).Text.ToString().Trim() + "',身份证号='" + ((TextBox)(GridView1.Rows[e.RowIndex].Cells[4].Controls[0])).Text.ToString().Trim() + "' where 编号='" + GridView1.DataKeys[e.RowIndex].Value.ToString() + "'";
SqlCommand com = new SqlCommand(sqlstr, con);
com.ExecuteNonQuery();
con.Close();
GridView1.EditIndex = -1;
bind();
}
}
这是为什么????? 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询