protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
this.GridView1.EditIndex = e.NewEditIndex; GridView1 .DataBind ();
} protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
SqlConnection sqlcon1 = new SqlConnection();
sqlcon1.ConnectionString = "Data Source=bea478ca30a0411;Initial Catalog=水上中心数据库;Integrated Security=True";
sqlcon1.Open();
string ath_ID = GridView1.DataKeys[e.RowIndex].Value.ToString();
string ath_name = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString();
string ath_sex = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[2].Controls[0])).Text.ToString();
string ath_birthday = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[3].Controls[0])).Text.ToString();
string ath_sbnum = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[4].Controls[0])).Text.ToString();
string ath_mz = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[5].Controls[0])).Text.ToString();
string ath_phone = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[6].Controls[0])).Text.ToString();
string ath_pa = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[7].Controls[0])).Text.ToString();
string ath_address = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[8].Controls[0])).Text.ToString();
string sqlstr = "update athlete_infor1 set ath_name='+ath_name+''',ath_sex='''+ath_sex+''',ath_birthday='''+ath_birthday+''',ath_sbnum='''+ath_sbnum+''',ath_mz='''+ath_mz+''',ath_phone='''+ath_phone+''',ath_pa='''+ath_pa+''',ath_address='''+ath_address+'''where ath_ID= '''+ ath_ID+'''";
SqlCommand mycmd = new SqlCommand(sqlstr, sqlcon1);
mycmd.ExecuteNonQuery();
mycmd.Dispose ();
sqlcon1.Close() ;
GridView1 .EditIndex =-1;
GridView1.DataBind();
}
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1;
GridView1.DataBind();
}
哪出了问题请高手帮个忙看看~~
{
this.GridView1.EditIndex = e.NewEditIndex; GridView1 .DataBind ();
} protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
SqlConnection sqlcon1 = new SqlConnection();
sqlcon1.ConnectionString = "Data Source=bea478ca30a0411;Initial Catalog=水上中心数据库;Integrated Security=True";
sqlcon1.Open();
string ath_ID = GridView1.DataKeys[e.RowIndex].Value.ToString();
string ath_name = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString();
string ath_sex = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[2].Controls[0])).Text.ToString();
string ath_birthday = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[3].Controls[0])).Text.ToString();
string ath_sbnum = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[4].Controls[0])).Text.ToString();
string ath_mz = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[5].Controls[0])).Text.ToString();
string ath_phone = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[6].Controls[0])).Text.ToString();
string ath_pa = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[7].Controls[0])).Text.ToString();
string ath_address = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[8].Controls[0])).Text.ToString();
string sqlstr = "update athlete_infor1 set ath_name='+ath_name+''',ath_sex='''+ath_sex+''',ath_birthday='''+ath_birthday+''',ath_sbnum='''+ath_sbnum+''',ath_mz='''+ath_mz+''',ath_phone='''+ath_phone+''',ath_pa='''+ath_pa+''',ath_address='''+ath_address+'''where ath_ID= '''+ ath_ID+'''";
SqlCommand mycmd = new SqlCommand(sqlstr, sqlcon1);
mycmd.ExecuteNonQuery();
mycmd.Dispose ();
sqlcon1.Close() ;
GridView1 .EditIndex =-1;
GridView1.DataBind();
}
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1;
GridView1.DataBind();
}
哪出了问题请高手帮个忙看看~~
改成这种 ath_name='"+ath_name+"',ath_sex='"+ath_sex+"'...然后断点。。跟踪你的SQL 生成的先拿到数据库中跑一下
这太乱了, set ath_name='\"+ath_name+\"',ath_sex='\"+ath_sex+\"',ath_birthday='\"+ath_birthday+\"'...
GridView1.DataSource=数据源;
,ath_sex='''+ath_sex+''',ath_birthday='''+ath_birthday+''',ath_sbnum='''+ath_sbnum+''',ath_mz='''+ath_mz+''',ath_phone='''+ath_phone+''',ath_pa='''+ath_pa+''',ath_address='''+ath_address+'''where ath_ID= '''+ ath_ID+'''";----这里面都是单引号??应该是类似'"+ath_name+"'吧