快乐的生活……

导航

[ASP.NET揭密读书笔记]ADO.NET介绍

一、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.


 

posted on 2006-06-26 17:26  小诈  阅读(2127)  评论(0编辑  收藏  举报