新人求SQL语句指点 小弟有一个gridview 数据是动态加载的 现在要实现gridview数据的更新 删除 不知道怎么写了求高手指教 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 gridview是asp.net中的吧?跟MSSQL有什么关系? 出门向上走 4层 到 NET区 咨询 protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e) {//取消编辑 GridView1.EditIndex = -1; studentdatashow();//数据绑定的方法 } protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e) {//点击编辑之后 GridView1.EditIndex = e.NewEditIndex; studentdatashow();//编辑之后的刷新数据绑定 } protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e) {//修改 SqlConnection con = DB.creatcon();//数据库连接 string uid = GridView1.DataKeys[e.RowIndex].Value.ToString(); GridViewRow row = GridView1.Rows[e.RowIndex]; TextBox tb1, tb2, tb3, tb4, tb5, tb6;//修改时的值所在文本框 tb1 = (TextBox)(row.Cells[2].Controls[0]); tb2 = (TextBox)(row.Cells[3].Controls[0]); tb3 = (TextBox)(row.Cells[4].Controls[0]); tb4 = (TextBox)(row.Cells[5].Controls[0]); tb5 = (TextBox)(row.Cells[6].Controls[0]); tb6 = (TextBox)(row.Cells[7].Controls[0]); string sql = "update t_studentinfo set userpwd='"+tb1.Text.Trim()+"',name='"+tb2.Text.Trim()+"',sex='"+tb3.Text.Trim()+"',birthday='"+tb4.Text.Trim()+"',address='"+tb5.Text.Trim()+"',telphone='"+tb6.Text.Trim()+"' where sid="+uid;//更新数据,sql写的很烂 见笑了 SqlCommand cmd = new SqlCommand(sql,con); cmd.ExecuteNonQuery();//执行语句 con.Close(); GridView1.EditIndex = -1;//确定之后 刷新数据 studentdatashow(); } protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) {//删除数据 string uid = GridView1.DataKeys[e.RowIndex].Value.ToString(); string sql = "delete from t_studentinfo where sid="+uid; SqlConnection con=DB.creatcon(); SqlCommand cmd = new SqlCommand(sql,con); cmd.ExecuteNonQuery(); con.Close(); studentdatashow(); } 请教group by和join一起使用的问题 SQLserver 2000数据库 和 sqlanyewhere 佣金报表按销售单数量2个及2个以上进行统计,请各位大虾指教 问个问题!~~ 有关事务的问题?看看我的存储过程有没什么问题? 6道关于SQL的选择题~~~谢谢大家哈~~~~ 一条有难度的SQL语句 保存数据? sql2005自定义函数中不允许执行拼接的SQL语句,是否可以创建clr 函数传入sql 并返回string? 求SQL 语句? 交叉取时间 解决了64位win7安装sql2005和2008远程连接不到其他数据库的方法
gridview是asp.net中的吧?跟MSSQL有什么关系?
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{//取消编辑
GridView1.EditIndex = -1;
studentdatashow();//数据绑定的方法
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{//点击编辑之后
GridView1.EditIndex = e.NewEditIndex;
studentdatashow();//编辑之后的刷新数据绑定
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{//修改
SqlConnection con = DB.creatcon();//数据库连接
string uid = GridView1.DataKeys[e.RowIndex].Value.ToString();
GridViewRow row = GridView1.Rows[e.RowIndex];
TextBox tb1, tb2, tb3, tb4, tb5, tb6;//修改时的值所在文本框
tb1 = (TextBox)(row.Cells[2].Controls[0]);
tb2 = (TextBox)(row.Cells[3].Controls[0]);
tb3 = (TextBox)(row.Cells[4].Controls[0]);
tb4 = (TextBox)(row.Cells[5].Controls[0]);
tb5 = (TextBox)(row.Cells[6].Controls[0]);
tb6 = (TextBox)(row.Cells[7].Controls[0]);
string sql = "update t_studentinfo set userpwd='"+tb1.Text.Trim()+"',name='"+tb2.Text.Trim()+"',sex='"+tb3.Text.Trim()+"',birthday='"+tb4.Text.Trim()+"',address='"+tb5.Text.Trim()+"',telphone='"+tb6.Text.Trim()+"' where sid="+uid;
//更新数据,sql写的很烂 见笑了
SqlCommand cmd = new SqlCommand(sql,con);
cmd.ExecuteNonQuery();//执行语句
con.Close();
GridView1.EditIndex = -1;//确定之后 刷新数据
studentdatashow();
}
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{//删除数据
string uid = GridView1.DataKeys[e.RowIndex].Value.ToString();
string sql = "delete from t_studentinfo where sid="+uid;
SqlConnection con=DB.creatcon();
SqlCommand cmd = new SqlCommand(sql,con);
cmd.ExecuteNonQuery();
con.Close();
studentdatashow();
}