关于更新数据,请大家帮忙,下午结帖!
public void MyDg_update(object Sender,System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
Label1.Text=e.Item.Cells[1].Text;// !取不出值来!
SqlConnection con=new SqlConnection("server=zhangzs;database=test;uid=sa;pwd=");
string updatecmd="update staff_inf set no='00123' where no='00'";//注意
SqlCommand ucmd=new SqlCommand(updatecmd,con);
con.Open();
MyDg.DataSource=ucmd.ExecuteReader();
MyDg.DataBind();
MyDg.EditItemIndex=-1;
con.Close();
string str="select name as 姓名,no as 工号,xueli as 学历,zhuzhi as 住址,dep as 部门 ,bynf as 毕业年份 from staff_inf ";
con.Open();
SqlCommand cmd =new SqlCommand(str,con);
MyDg.DataSource=cmd.ExecuteReader();
MyDg.DataBind();
con.Close();
}
跟昨天的是一个,也就是DataGrid添加EditCommandColumn之后,当点"update"是,应该是sql server 中的数据更新!
上面是相应部分的代码,我遇到的问题是:
1.我并不能取出相应记录的,第2列的text值(我是用一个label测试的)
2.可以这样写string updatecmd="update staff_inf set no='00123' where no=Label.Text" 吗?
我在指定具体的no时是可以修改的,也就是代码里写的那样!
我哪写错了,请费心指导一下,谢谢!