标题:求助GridView控件中数据更新问题
取消只看楼主
stonefang
Rank: 1
等 级:新手上路
帖 子:163
专家分:0
注 册:2007-3-20
 问题点数:0 回复次数:2 
求助GridView控件中数据更新问题
下面是VS03里更新DataGrid的代码,怎么改为GridView下的更新代码?请指点.
string st_sqlstr = "update ST_teacher set ST_Teacher_name=@teacher_name,ST_Teacher_college=@teacher_college where ST_Teacher_id=@teacher_id";
SqlCommand st_comm = new SqlCommand(st_sqlstr, con);
st_comm.Parameters.Add(new SqlParameter("@teacher_name", SqlDbType.VarChar, 50));
st_comm.Parameters.Add(new SqlParameter("@teacher_college", SqlDbType.VarChar, 50));
st_comm.Parameters.Add(new SqlParameter("@teacher_id", SqlDbType.VarChar, 50));
string st_colvalue = ((TextBox)e.Item.Cells[2].Controls[0]).Text;
st_comm.Parameters["@teacher_name"].Value = st_colvalue;
st_colvalue = ((TextBox)e.Item.Cells[3].Controls[0]).Text;
st_comm.Parameters["@teacher_college"].Value = st_colvalue;
st_comm.Parameters["@teacher_id"].Value = st_dtg_teacher.DataKeys[(int)e.Item.ItemIndex];
st_comm.Connection.Open();
try
{
st_comm.ExecuteNonQuery();
Lbl_note.Text = "编辑成功";
Gv_teach.EditItemIndex = -1;
}
catch (SqlException)
{
Lbl_note.Text = "编辑失败";
Lbl_note.Style["color"] = "red";
}
st_comm.Connection.Close();
St_BindGridView();
搜索更多相关主题的帖子: GridView 控件 数据 
2007-05-15 21:30
stonefang
Rank: 1
等 级:新手上路
帖 子:163
专家分:0
注 册:2007-3-20
得分:0 
gridview中删除数据,我写了如下代码,但不能删除,请高人指点.
SqlConnection con = DB.CreateConn();
st_sqlstr = "delete from Teacher where Teaher_id='"+this.Gv_teach.DataKeys[e.RowIndex].Value+"'";
con.Open();
SqlCommand cmd = new SqlCommand(st_sqlstr,con);
cmd.ExecuteNonQuery();
Response.Write("<script language='javascript'>alert('删除成功')</script>");
St_BindGridView();

我就是我! 从那跌到从那爬起! E-mail:fangguang2008@
2007-05-18 23:10
stonefang
Rank: 1
等 级:新手上路
帖 子:163
专家分:0
注 册:2007-3-20
得分:0 
没有出错,就是点了没反映,

我就是我! 从那跌到从那爬起! E-mail:fangguang2008@
2007-05-20 19:48



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-139676-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.162584 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved