none
dataAdapter.Update(dataSet)是否有像BeginTransaction()功能 RRS feed

  • 問題

  • dataAdapter.Update(dataSet)是否有像BeginTransaction()功能,因找help文件裏是說"更新資料列成功後,對該資料列的變更將被接受。"但我有多個update要做

    謝謝!

    2006年9月26日 上午 08:21

解答

  • SqlConnection _Connection = new SqlConnection(ConnectionString);

    SqlTransaction _Transaction = _Connection.BeginTransaction();

    SqlDataAdapter DataAdapter = new SqlDataAdapter("SELECT * FROM aaa",_Connection ;

    try

         DataAdapter.InsertCommand = CommandBuilder.GetInsertCommand();
         DataAdapter.UpdateCommand = ProcessCommandText(CommandBuilder.GetUpdateCommand(), rows[0].Table.TableName);
         DataAdapter.DeleteCommand = ProcessCommandText(CommandBuilder.GetDeleteCommand(), rows[0].Table.TableName);
         DataAdapter.InsertCommand.Transaction = _Transaction ;
         DataAdapter.UpdateCommand.Transaction = _Transaction ;
         DataAdapter.DeleteCommand.Transaction = _Transaction ;

    DataAdapter.Update(rows);

    _Transaction.Commit();

    }

        catch (Exception ex) {
          _Transaction.Rollback();
        }

    2006年9月26日 上午 08:31

所有回覆

  • SqlConnection _Connection = new SqlConnection(ConnectionString);

    SqlTransaction _Transaction = _Connection.BeginTransaction();

    SqlDataAdapter DataAdapter = new SqlDataAdapter("SELECT * FROM aaa",_Connection ;

    try

         DataAdapter.InsertCommand = CommandBuilder.GetInsertCommand();
         DataAdapter.UpdateCommand = ProcessCommandText(CommandBuilder.GetUpdateCommand(), rows[0].Table.TableName);
         DataAdapter.DeleteCommand = ProcessCommandText(CommandBuilder.GetDeleteCommand(), rows[0].Table.TableName);
         DataAdapter.InsertCommand.Transaction = _Transaction ;
         DataAdapter.UpdateCommand.Transaction = _Transaction ;
         DataAdapter.DeleteCommand.Transaction = _Transaction ;

    DataAdapter.Update(rows);

    _Transaction.Commit();

    }

        catch (Exception ex) {
          _Transaction.Rollback();
        }

    2006年9月26日 上午 08:31
  • 速沛小子謝謝你的幫忙,已解決問題了
    2006年10月5日 上午 12:19