private void DataGrid1_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
string updateCmd="update Socut_BBS set";
updateCmd+="Poster ='"+((TextBox)e.Item.Cells[1].FindControl("TextBox1")).Text+"'";
updateCmd+=" where ID ="+DataGrid1.DataKeys[(int)e.Item.ItemIndex].ToString();
oleDbCommand1.CommandText=updateCmd;
oleDbCommand1.Connection.Open();
oleDbCommand1.ExecuteNonQuery();
oleDbCommand1.Connection.Close();
oleDbDataAdapter1.Fill(myDataSet1);
DataGrid1.EditItemIndex=-1;
DataGrid1.DataBind();
博客给出了一个DataGrid更新命令的代码示例。代码中定义了更新命令字符串,通过获取TextBox的值更新数据库中Socut_BBS表的Poster字段,执行更新操作后关闭连接,重新填充数据集并绑定DataGrid。
692

被折叠的 条评论
为什么被折叠?



