怎么把DataGird修改的数据回滚到SQL数据库中

解决方案 »

  1.   

    我写的一个方法,分享一下吧:
    public static void UpdateByDataSet(DataSet ds, string strTblName)
            {
                //string strTblName = ds.Tables[0].TableName.Trim();
                try
                {
                    SqlConnection  conn = new SqlConnection(connectionString);
             
                    SqlDataAdapter myAdapter = new SqlDataAdapter();
                    SqlCommand myCommand = new SqlCommand("select * from " + strTblName, conn);    
                    myAdapter.SelectCommand = myCommand;
                    SqlCommandBuilder myCommandBuilder = new SqlCommandBuilder(myAdapter);     
                    myAdapter.Update(ds.Tables[0]);  
                }
                catch(Exception x)
                {
                    throw new Exception(x.Message);
                }   
            }