就是这样:update 表 set 列="......" where 列=(临时表数据)
可以实现吗?小弟要保存datagrid表格中的数据,临时表中的数据是在datagrid中修改过的。
急!分不够再加!

解决方案 »

  1.   

    update 表 set 列="......" where 列 in (select column from 临时表 where 条件)
      

  2.   

    这是临时表,也就是只存在于内存中的表,也就是datatable,该怎样做?高手帮忙呀!
      

  3.   

    给你段源码,你参考一下:
    使用的是access数据库,对datagrid中的数据编辑、修改、删除,并保存到数据库中。 private void Page_Load(object sender, System.EventArgs e)
    {
    // 在此处放置用户代码以初始化页面
    string MyconnString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+Server.MapPath("/dg测试/bbs1.mdb");
    Myconn=new OleDbConnection(MyconnString);
    Myconn.Open();
    if(!Page.IsPostBack)
    {
    BindGrid();
    }
    } ICollection CreateTable()
    {
    string strSel="Select UserId,UserName,UserPass,UserAccount,UserQQ from Users";
    DataSet ds=new DataSet();
    OleDbDataAdapter MyAdapter=new OleDbDataAdapter(strSel,Myconn);
    MyAdapter.Fill(ds,"table1");
    return ds.Tables["table1"].DefaultView;
    }
    protected  void BindGrid()
    {
    dgUser.DataSource=CreateTable();
    dgUser.DataBind();
    }
    private void DataGrid_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e) 

    if(e.CommandName=="Delete") 

    string MyconnString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+Server.MapPath("/dg测试/bbs1.mdb");
    OleDbConnection conn=new OleDbConnection(MyconnString);
        OleDbCommand comm=new OleDbCommand("delete from Users where UserId=@id",conn); 
        OleDbParameter parm1=new OleDbParameter("@id",OleDbType.VarChar); 
        parm1.Value=this.dgUser.DataKeys[e.Item.ItemIndex]; 
        comm.Parameters.Add(parm1); 
        conn.Open(); 
        comm.ExecuteNonQuery(); 
        conn.Close(); 
        BindGrid();

    }  protected  void DataGrid_EditCommand(Object sender,DataGridCommandEventArgs e)
    {
    dgUser.EditItemIndex=(int)e.Item.ItemIndex;
    BindGrid();
    } protected  void DataGrid_CancelCommand(Object sender,DataGridCommandEventArgs e)
    {
    dgUser.EditItemIndex=-1;
    BindGrid();
    }
           protected void DataGrid_PageChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e) 
    {
    this.dgUser.CurrentPageIndex=e.NewPageIndex;
    BindGrid(); 

    protected void DataGrid_UpdateCommand(Object sender,DataGridCommandEventArgs e)
    {
    string strName = e.Item.Cells[1].Text;
    string strPass = ((TextBox)e.Item.Cells[2].Controls[0]).Text;
    string strAccount =((TextBox)e.Item.Cells[3].Controls[0]).Text;
    int intQQ = Int32.Parse(((TextBox)e.Item.Cells[4].Controls[0]).Text);
    string strUpdate="Update Users set UserPass='"+ strPass +"',UserAccount='"+ strAccount +"',UserQQ='"+ intQQ +"' Where UserName='"+strName+"'";
    OleDbCommand Mycomm=new OleDbCommand(strUpdate,Myconn);
    try
    {
    Mycomm.ExecuteNonQuery();
    Response.Write("成功操作数据库");
    }
    catch
    {
    Response.Write(Myconn.ConnectionString + "更新数据库失败....<BR>");
    }
    finally
    {
    Myconn.Close();
    } dgUser.EditItemIndex=-1;
    BindGrid();
    }
    #region Web 窗体设计器生成的代码
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
    //
    InitializeComponent();
    base.OnInit(e);
    }

    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {    
    this.dgUser.EditCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid_EditCommand);
    this.dgUser.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid_ItemCommand);
    this.Load += new System.EventHandler(this.Page_Load); }
    #endregion
    }
    }