Gridview编辑问题 更新功能无效
protectedvoidGridView1_RowUpdating(objectsender,GridViewUpdateEventArgse){stringaid=G...
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
string aid = GridView1.DataKeys[e.RowIndex].Value.ToString();
string title = ((TextBox)GridView1.Rows[e.RowIndex].Cells[1].Controls[0]).Text.ToString();
string fanwei = ((TextBox)GridView1.Rows[e.RowIndex].Cells[2].Controls[0]).Text.ToString();
string renshu = ((TextBox)GridView1.Rows[e.RowIndex].Cells[3].Controls[0]).Text.ToString();
string feiyong = ((TextBox)GridView1.Rows[e.RowIndex].Cells[4].Controls[0]).Text.ToString();
string date = ((TextBox)GridView1.Rows[e.RowIndex].Cells[5].Controls[0]).Text.ToString();
string baomingjiezhi = ((TextBox)GridView1.Rows[e.RowIndex].Cells[6].Controls[0]).Text.ToString();
string jieshushijian = ((TextBox)GridView1.Rows[e.RowIndex].Cells[7].Controls[0]).Text.ToString();
string tel = ((TextBox)GridView1.Rows[e.RowIndex].Cells[8].Controls[0]).Text.ToString();
string amiaoshu = ((TextBox)GridView1.Rows[e.RowIndex].Cells[9].Controls[0]).Text.ToString();
SqlConnection conn = new SqlConnection("server=(local);database=Data;integrated security=sspi");
conn.Open();
SqlCommand cmd = new SqlCommand("update activy set title=@title,fanwei=@fanwei,renshu=@renshu,feiyong=@feiyong,date=@date,baomingjiezhi=@baomingjiezhi,jieshushijian=@jieshushijian,tel=@tel,amiaoshu=@amiaoshu where aid=@aid", conn);
SqlParameter sp1 = new SqlParameter("@aid", aid);
SqlParameter sp2 = new SqlParameter("@title", title);
SqlParameter sp3 = new SqlParameter("@fanwei", fanwei);
SqlParameter sp4 = new SqlParameter("@renshu", renshu);
SqlParameter sp5 = new SqlParameter("@feiyong", feiyong);
SqlParameter sp6 = new SqlParameter("@date", date);
SqlParameter sp7 = new SqlParameter("@baomingjiezhi", baomingjiezhi);
SqlParameter sp8 = new SqlParameter("@jieshushijian", jieshushijian);
SqlParameter sp9 = new SqlParameter("@tel", tel);
SqlParameter sp10 = new SqlParameter("@amiaoshu", amiaoshu);
cmd.Parameters.Add(sp1);
cmd.Parameters.Add(sp2);
cmd.Parameters.Add(sp3);
cmd.Parameters.Add(sp4);
cmd.Parameters.Add(sp5);
cmd.Parameters.Add(sp6);
cmd.Parameters.Add(sp7);
cmd.Parameters.Add(sp8);
cmd.Parameters.Add(sp9);
cmd.Parameters.Add(sp10);
cmd.ExecuteNonQuery();
conn.Close();
GridView1.EditIndex = -1;
GridViewBind();
}
并不报错,但是没有更新 ,如果去掉数据库绑定时string sql = "select * from buildings where username='" + username + "'"; 中的username=username 就能实现功能,为什么啊 展开
{
string aid = GridView1.DataKeys[e.RowIndex].Value.ToString();
string title = ((TextBox)GridView1.Rows[e.RowIndex].Cells[1].Controls[0]).Text.ToString();
string fanwei = ((TextBox)GridView1.Rows[e.RowIndex].Cells[2].Controls[0]).Text.ToString();
string renshu = ((TextBox)GridView1.Rows[e.RowIndex].Cells[3].Controls[0]).Text.ToString();
string feiyong = ((TextBox)GridView1.Rows[e.RowIndex].Cells[4].Controls[0]).Text.ToString();
string date = ((TextBox)GridView1.Rows[e.RowIndex].Cells[5].Controls[0]).Text.ToString();
string baomingjiezhi = ((TextBox)GridView1.Rows[e.RowIndex].Cells[6].Controls[0]).Text.ToString();
string jieshushijian = ((TextBox)GridView1.Rows[e.RowIndex].Cells[7].Controls[0]).Text.ToString();
string tel = ((TextBox)GridView1.Rows[e.RowIndex].Cells[8].Controls[0]).Text.ToString();
string amiaoshu = ((TextBox)GridView1.Rows[e.RowIndex].Cells[9].Controls[0]).Text.ToString();
SqlConnection conn = new SqlConnection("server=(local);database=Data;integrated security=sspi");
conn.Open();
SqlCommand cmd = new SqlCommand("update activy set title=@title,fanwei=@fanwei,renshu=@renshu,feiyong=@feiyong,date=@date,baomingjiezhi=@baomingjiezhi,jieshushijian=@jieshushijian,tel=@tel,amiaoshu=@amiaoshu where aid=@aid", conn);
SqlParameter sp1 = new SqlParameter("@aid", aid);
SqlParameter sp2 = new SqlParameter("@title", title);
SqlParameter sp3 = new SqlParameter("@fanwei", fanwei);
SqlParameter sp4 = new SqlParameter("@renshu", renshu);
SqlParameter sp5 = new SqlParameter("@feiyong", feiyong);
SqlParameter sp6 = new SqlParameter("@date", date);
SqlParameter sp7 = new SqlParameter("@baomingjiezhi", baomingjiezhi);
SqlParameter sp8 = new SqlParameter("@jieshushijian", jieshushijian);
SqlParameter sp9 = new SqlParameter("@tel", tel);
SqlParameter sp10 = new SqlParameter("@amiaoshu", amiaoshu);
cmd.Parameters.Add(sp1);
cmd.Parameters.Add(sp2);
cmd.Parameters.Add(sp3);
cmd.Parameters.Add(sp4);
cmd.Parameters.Add(sp5);
cmd.Parameters.Add(sp6);
cmd.Parameters.Add(sp7);
cmd.Parameters.Add(sp8);
cmd.Parameters.Add(sp9);
cmd.Parameters.Add(sp10);
cmd.ExecuteNonQuery();
conn.Close();
GridView1.EditIndex = -1;
GridViewBind();
}
并不报错,但是没有更新 ,如果去掉数据库绑定时string sql = "select * from buildings where username='" + username + "'"; 中的username=username 就能实现功能,为什么啊 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询