vs.net中DataGrid控件修改后相应的数据库也修改,怎么实现??

来源:百度知道 编辑:UC知道 时间:2024/05/13 09:12:55
用简单的方法

谢谢

你可以用sqlcommandBuilder 创建sqlcommandBuilder(adapter)对象,再得到adapter.updatecommend ,用的时候在调用就行了啊!

不知道你是不是做asp.net的
protected void dginfo_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
String id = dginfo.DataKeys[e.RowIndex][0].ToString();
TextBox tb = (TextBox)dginfo.Rows[e.RowIndex].Cells[3].FindControl("address");
String textaddress = tb.Text;
using (SqlCommand comm = new SqlCommand("update employees set address='" + textaddress + "' where employeeid='" + id + "'", conn))
{
conn.Open();
comm.ExecuteNonQuery();
conn.Close();
}
dginfo.EditIndex = -1;
dginfoDatabind();
}

你要在datekeynames上绑定好你的数据id;

javascrpitp里是这样的:
<asp:TemplateField HeaderText="地址">
<ItemTemplate>