[ASP.NET揭密讀書筆記]ADO.NET介紹

來源:互聯網
上載者:User

一、Creating an ASP.NET Page Transaction--頁面事務
Finally, you can create a transaction at the level of an ASP.NET page. You can enroll an ASP.NET page in a transaction by adding one of the following page directives to the ASP.NET page:

Disabled— Transactions are disabled for the page. This is the default value.

NotSupported— Indicates that the page does not execute within a transaction.

Supported— If a transaction already exists, the page will execute within the context of the transaction. However, it will not create a new transaction.

Required— If a transaction already exists, the page will execute within the context of the transaction. If a transaction does not exist, it will create a new one.

RequiresNew— Creates a new transaction for each request.

Try
  cmdUpdateAccountA.ExecuteNonQuery()
  cmdUpdateAccountB.ExecuteNonQuery()

  ' Commit the transaction
  ContextUtil.SetComplete()
  Response.Write( "Transaction Successful!" )
Catch ex As Exception
  ContextUtil.SetAbort()
  Response.Write( "Transaction Failed!" )
Finally
  conBank.Close()

二、Specifying a Command Behavior,可以擷取第一個記錄,表的結構資訊等
When you call the ExecuteReader() method of the Command object you can pass an optional CommandBehavior parameter. By supplying the CommandBehavior parameter, you can gain greater control over how the ExecuteReader() method retrieves data from a database.

The CommandBehavior enumeration has the following values:

CloseConnection— Automatically closes an open database connection after the DataReader is closed.

KeyInfo— Retrieves column and primary key with the data. Executes the query with the FOR BROWSE clause.

SchemaOnly— Retrieves column and table schema information without retrieving data.

SequentialAccess— Enables access to database columns that contain a large amount of information.

SingleResult— Optimizes the command to retrieve only a single result.

SingleRow— Optimizes the command to retrieve only a single row. If multiple rows are returned, additional rows are discarded.

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.