SqlDataSourceView 類別

定義

支援 SqlDataSource 控制項,並提供資料繫結控制項的介面,以便對關聯式資料庫執行 SQL 資料作業。Supports the SqlDataSource control and provides an interface for data-bound controls to perform SQL data operations against relational databases.

public ref class SqlDataSourceView : System::Web::UI::DataSourceView, System::Web::UI::IStateManager
public class SqlDataSourceView : System.Web.UI.DataSourceView, System.Web.UI.IStateManager
type SqlDataSourceView = class
    inherit DataSourceView
    interface IStateManager
Public Class SqlDataSourceView
Inherits DataSourceView
Implements IStateManager
繼承
SqlDataSourceView
衍生
實作

備註

SqlDataSourceView類別主要是用來供資料繫結控制項使用,而不是作為頁面程式碼中的可程式化物件。The SqlDataSourceView class is intended primarily to be used by data-bound controls, and not as a programmable object in page code.

ASP.NET 資料來源控制項包含一或多個資料清單,並以資料來源 view 物件表示。ASP.NET data source controls contain one or more lists of data, represented by data source view objects. SqlDataSourceView類別 DataSourceView 會擴充類別、定義與其相關聯之控制項的功能 SqlDataSource ,並為數據源控制項執行基本資料功能。The SqlDataSourceView class extends the DataSourceView class, defines the capabilities of the SqlDataSource control with which it is associated, and implements the basic data functionality for the data source control. SqlDataSourceView類別會為控制項執行資料功能 SqlDataSource ,包括 SelectUpdateInsertDelete 作業、排序、篩選,以及管理保留在顯示狀態中的設定。The SqlDataSourceView class implements the data functionality for the SqlDataSource control, including the Select, Update, Insert, and Delete operations, sorting, filtering, and managing settings that are kept in view state.

雖然 SqlDataSourceView 物件不會直接公開給控制項的網頁開發人員 SqlDataSource ,但它的許多屬性都是。Although the SqlDataSourceView object is not directly exposed to page developers by the SqlDataSource control, many of its properties are. 資料來源視圖所執行的最基本作業,是使用方法從基礎資料庫抓取資料 Select ,以抓取 IEnumerable 資料項目的集合。The most basic operation that a data source view performs is data retrieval from the underlying database using the Select method, which retrieves an IEnumerable collection of data items. SqlDataSourceView類別會使用 SQL 查詢,從關係資料庫執行資料抓取。The SqlDataSourceView class implements data retrieval from relational databases using SQL queries. 您可以將 SQL 查詢參數化,以提供更大的彈性和安全性。The SQL queries can be parameterized for greater flexibility and security. 下列資料抓取方法、屬性和事件都是由所執行, SqlDataSourceView 並由其控制項直接公開 SqlDataSource 給頁面開發人員和其他呼叫者:The following data retrieval methods, properties, and events are implemented by the SqlDataSourceView and exposed directly by its SqlDataSource control to page developers and other callers:

SqlDataSourceView物件支援使用 SQL 命令來更新關係資料庫中的資料。The SqlDataSourceView object supports updating data in a relational database using SQL commands. 您可以將 SQL 命令參數化,以提供更大的彈性和安全性。The SQL commands can be parameterized for greater flexibility and security. 資料繫結控制項(例如 GridViewDetailsView )可以設定為使用自動執行更新 SqlDataSourceView ,其他控制項則不能。Data-bound controls, such as the GridView and DetailsView, can be configured to perform updates automatically using the SqlDataSourceView, while other controls cannot. 下列的更新方法、屬性和事件都是由所執行, SqlDataSourceView 並由其控制項直接公開 SqlDataSource 給網頁開發人員和其他呼叫者:The following update methods, properties, and events are implemented by the SqlDataSourceView and exposed directly by its SqlDataSource control to page developers and other callers:

SqlDataSourceView支援將新的資料列插入關係資料庫中。The SqlDataSourceView supports inserting new rows of data into a relational database. 您可以將屬性中所指定的 SQL 命令 InsertCommand 參數化,以提供更大的彈性和安全性。The SQL commands that are specified in the InsertCommand property can be parameterized for greater flexibility and security. 資料繫結控制項(例如 GridViewDetailsView )可以設定為使用自動執行插入 SqlDataSourceView ,其他控制項則不能。Data-bound controls, such as the GridView and DetailsView, can be configured to perform inserts automatically using the SqlDataSourceView, while other controls cannot. 下列插入方法、屬性和事件是由所執行, SqlDataSourceView 並直接由其控制項公開 SqlDataSource 給頁面開發人員和其他呼叫者:The following insert methods, properties, and events are implemented by the SqlDataSourceView and exposed directly by its SqlDataSource control to page developers and other callers:

SqlDataSourceView物件也支援從關係資料庫刪除資料。The SqlDataSourceView object also supports deleting data from a relational database. 如同其他命令一樣,在屬性中指定的 SQL 命令 DeleteCommand 也可以參數化,以提供更大的彈性和安全性。As with other commands, the SQL commands that are specified in the DeleteCommand property can be parameterized for greater flexibility and security. 資料繫結控制項(例如 GridViewDetailsView )可以設定為使用自動執行刪除 SqlDataSourceView ,其他控制項則不能。Data-bound controls, such as the GridView and DetailsView, can be configured to perform deletes automatically using the SqlDataSourceView, while other controls cannot. 下列的 delete 方法、屬性和事件都是由所執行, SqlDataSourceView 並由其控制項直接公開 SqlDataSource 給網頁開發人員和其他呼叫者:The following delete methods, properties, and events are implemented by the SqlDataSourceView and exposed directly by its SqlDataSource control to page developers and other callers:

當資料抓取期間用來篩選資料的子句為動態時,資料抓取功能更強大。Data retrieval is more powerful when the clause that is used to filter the data during data retrieval is dynamic. 換句話說,使用靜態 WHERE 子句的 SQL 查詢不像 SQL 查詢一樣具彈性且功能強大,其中 WHERE 子句中的值會系結至可能變更的值,例如 Web Form 頁面的控制項中顯示的值。In other words, an SQL query with a static WHERE clause is not as flexible and powerful as an SQL query where the values in the WHERE clause are bound to values that can change, such as values that are displayed in controls on a Web Forms page. SelectCommand您可以使用 FilterExpressionFilterParameters 屬性,將動態篩選套用至資料抓取,而不需要在每個頁面載入時重建 SQL 查詢和設定屬性。Instead of rebuilding an SQL query and setting the SelectCommand property on every page load, you can use the FilterExpression and FilterParameters properties to apply dynamic filtering to data retrieval. 這些屬性是由執行 SqlDataSourceView ,並由其控制項直接公開 SqlDataSource 至資料繫結控制項和其他呼叫者。These properties are implemented by the SqlDataSourceView and exposed directly by its SqlDataSource control to data-bound controls and other callers.

您可以藉由加入 ORDER BY 子句來排序您以控制項取出的資料 SqlDataSource ,這會讓資料庫在您抓取資料時執行排序,或在抓取資料之後將資料排序在記憶體中。You can sort the data that you retrieve with the SqlDataSource control by adding an ORDER BY clause, which causes the database to perform the ordering for you when you retrieve data or by ordering the data in memory after it is retrieved. 您可以藉 SqlDataSourceView 由設定 SortExpression DataSourceSelectArguments 傳遞給方法之物件的屬性,將排序運算式提供給 SelectYou can supply a sorting expression to the SqlDataSourceView by setting the SortExpression property of the DataSourceSelectArguments object that is passed to the Select method. 屬性的語法與 SortExpression 屬性的語法相同 DataView.SortThe syntax for the SortExpression property is the same as the syntax for a DataView.Sort property. 如果您使用預存程式來取出資料,您也可以使用 SortParameterName 屬性來指定用來排序預存程序呼叫結果的參數。If you use a stored procedure to retrieve data, you can also use the SortParameterName property to specify a parameter that is used specifically for sorting the results of a stored procedure call.

如果有一位以上的使用者可以同時變更資料庫,則可能會發生並行衝突。When more than one user can change the database concurrently, there is the potential for concurrency conflict. SqlDataSource控制項具有透過屬性的並行控制 SqlDataSource.ConflictDetectionThe SqlDataSource control has controls concurrency through the SqlDataSource.ConflictDetection property. 這項功能會在屬性中實作為 SqlDataSourceView.ConflictDetectionThe functionality is implemented in the SqlDataSourceView.ConflictDetection property.

就像許多其他 Web 服務器控制項一樣,會執行 SqlDataSourceView IStateManager 介面並使用 view state 來追蹤頁面要求之間的狀態。Like many other Web server controls, the SqlDataSourceView implements the IStateManager interface and uses view state to track its state across page requests. 系統 IsTrackingViewState 會提供和屬性的實和 LoadViewState 、和方法, SaveViewState TrackViewState 以啟用控制項的檢視狀態追蹤。Implementations of the IsTrackingViewState and property and the LoadViewState, SaveViewState, and TrackViewState methods are provided to enable view state tracking for the control. 如需詳細資訊,請參閱 ASP.NET 狀態管理總覽For more information, see ASP.NET State Management Overview.

建構函式

SqlDataSourceView(SqlDataSource, String, HttpContext)

將指定之 SqlDataSourceView 控制項設定為目前檢視的擁有人,初始化 SqlDataSource 類別的新執行個體。Initializes a new instance of the SqlDataSourceView class setting the specified SqlDataSource control as the owner of the current view.

屬性

CancelSelectOnNullParameter

取得或設定值,指出當 SelectParameters 集合中包含的任何參數評估為 null 時,是否取消資料擷取作業。Gets or sets a value indicating whether a data retrieval operation is canceled when any parameter that is contained in the SelectParameters collection evaluates to null.

CanDelete

取得值,指出與目前 SqlDataSourceView 控制項關聯的 SqlDataSource 物件是否支援刪除作業。Gets a value indicating whether the SqlDataSourceView object that is associated with the current SqlDataSource control supports the delete operation.

CanInsert

取得值,指出與目前 SqlDataSourceView 控制項關聯的 SqlDataSource 物件是否支援插入作業。Gets a value indicating whether the SqlDataSourceView object that is associated with the current SqlDataSource control supports the insert operation.

CanPage

取得值,指出與目前 SqlDataSourceView 控制項關聯的 SqlDataSource 物件是否支援對擷取的資料進行分頁。Gets a value indicating whether the SqlDataSourceView object that is associated with the current SqlDataSource control supports the paging of retrieved data.

CanRetrieveTotalRowCount

取得值,指出與目前 SqlDataSourceView 控制項關聯的 SqlDataSource 物件是否除了支援擷取資料集以外,還支援擷取資料列的總數。Gets a value indicating whether the SqlDataSourceView object that is associated with the current SqlDataSource control supports retrieving the total number of data rows, in addition to the set of data.

CanSort

取得值,指出與目前 SqlDataSourceView 控制項關聯的 SqlDataSource 物件是否支援對所擷取資料的排序檢視。Gets a value indicating whether the SqlDataSourceView object that is associated with the current SqlDataSource control supports a sorted view on the retrieved data.

CanUpdate

取得值,指出與目前 SqlDataSourceView 控制項關聯的 SqlDataSource 物件是否支援更新作業。Gets a value indicating whether the SqlDataSourceView object that is associated with the current SqlDataSource control supports the update operation.

ConflictDetection

取得或設定值,指出在作業期間,當基礎資料庫的資料列資料發生變更時,SqlDataSource 控制項如何執行更新和刪除作業。Gets or sets the value indicating how the SqlDataSource control performs updates and deletes when data in a row in the underlying database changes during the time of the operation.

DeleteCommand

取得或設定 SQL 字串,SqlDataSourceView 會用來刪除基礎資料庫的資料。Gets or sets the SQL string that the SqlDataSourceView uses to delete data from the underlying database.

DeleteCommandType

取得或設定值,指出 DeleteCommand 屬性中的文字是 SQL 陳述式還是預存程序的名稱。Gets or sets a value indicating whether the text in the DeleteCommand property is a SQL statement or the name of a stored procedure.

DeleteParameters

取得包含 DeleteCommand 屬性所用參數的參數集合。Gets the parameters collection containing the parameters that are used by the DeleteCommand property.

Events

取得資料來源檢視的事件處理常式委派清單。Gets a list of event-handler delegates for the data source view.

(繼承來源 DataSourceView)
FilterExpression

取得或設定當呼叫 Select 時會套用的篩選運算式。Gets or sets a filtering expression that is applied when the Select method is called.

FilterParameters

取得與 FilterExpression 字串中任何參數替代符號關聯的參數集合。Gets a collection of parameters that are associated with any parameter placeholders in the FilterExpression string.

InsertCommand

取得或設定 SQL 字串,SqlDataSourceView 物件會用來將資料插入基礎資料庫。Gets or sets the SQL string that the SqlDataSourceView object uses to insert data into the underlying database.

InsertCommandType

取得或設定值,指出 InsertCommand 屬性中的文字是 SQL 陳述式還是預存程序的名稱。Gets or sets a value indicating whether the text in the InsertCommand property is a SQL statement or the name of a stored procedure.

InsertParameters

取得包含 InsertCommand 屬性所用參數的參數集合。Gets the parameters collection containing the parameters that are used by the InsertCommand property.

IsTrackingViewState

取得值,指出 SqlDataSourceView 物件是否正在將變更儲存到它的檢視狀態。Gets a value indicating whether the SqlDataSourceView object is saving changes to its view state.

Name

取得資料來源檢視的名稱。Gets the name of the data source view.

(繼承來源 DataSourceView)
OldValuesParameterFormatString

取得或設定格式字串,套用至傳遞給 DeleteUpdate 方法之任何參數的名稱。Gets or sets a format string to apply to the names of any parameters that are passed to the Delete or Update method.

ParameterPrefix

取得字串,用於將參數替代符號做為參數型 SQL 查詢中的前置詞。Gets the string that is used to prefix a parameter placeholder in a parameterized SQL query.

SelectCommand

取得或設定 SQL 字串,SqlDataSourceView 物件會用來擷取基礎資料庫的資料。Gets or sets the SQL string that the SqlDataSourceView object uses to retrieve data from the underlying database.

SelectCommandType

取得或設定值,指出 SelectCommand 屬性中的文字為 SQL 查詢還是預存程序的名稱。Gets or sets a value indicating whether the text in the SelectCommand property is a SQL query or the name of a stored procedure.

SelectParameters

取得包含 SelectCommand 屬性所用參數的參數集合。Gets the parameters collection containing the parameters that are used by the SelectCommand property.

SortParameterName

取得或設定預存程序參數的名稱,用於在使用預存程序執行資料擷取時,對擷取的資料進行排序。Gets or sets the name of a stored procedure parameter that is used to sort retrieved data when data retrieval is performed using a stored procedure.

UpdateCommand

取得或設定 SQL 字串,SqlDataSourceView 物件會用來更新基礎資料庫的資料。Gets or sets the SQL string that the SqlDataSourceView object uses to update data in the underlying database.

UpdateCommandType

取得或設定值,指出 UpdateCommand 屬性中的文字是 SQL 陳述式還是預存程序的名稱。Gets or sets a value indicating whether the text in the UpdateCommand property is a SQL statement or the name of a stored procedure.

UpdateParameters

取得包含 UpdateCommand 屬性所用參數的參數集合。Gets the parameters collection containing the parameters that are used by the UpdateCommand property.

方法

CanExecute(String)

判斷是否可以執行指定的命令。Determines whether the specified command can be executed.

(繼承來源 DataSourceView)
Delete(IDictionary, IDictionary)

使用 DeleteCommand SQL 字串、DeleteParameters 集合中指定的任何參數,以及 keysoldValues 集合中指定的值,執行刪除作業。Performs a delete operation using the DeleteCommand SQL string, any parameters that are specified in the DeleteParameters collection, and the values that are in the specified keys and oldValues collections.

Delete(IDictionary, IDictionary, DataSourceViewOperationCallback)

DataSourceView 物件表示的資料清單上,執行非同步刪除作業。Performs an asynchronous delete operation on the list of data that the DataSourceView object represents.

(繼承來源 DataSourceView)
Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(繼承來源 Object)
ExecuteCommand(String, IDictionary, IDictionary)

執行指定命令。Executes the specified command.

(繼承來源 DataSourceView)
ExecuteCommand(String, IDictionary, IDictionary, DataSourceViewOperationCallback)

執行指定命令。Executes the specified command.

(繼承來源 DataSourceView)
ExecuteDelete(IDictionary, IDictionary)

使用 DeleteCommand SQL 字串、DeleteParameters 集合中指定的任何參數,以及 keysoldValues 集合中指定的值,執行刪除作業。Performs a delete operation using the DeleteCommand SQL string, any parameters that are specified in the DeleteParameters collection, and the values that are in the specified keys and oldValues collections.

ExecuteInsert(IDictionary)

使用 InsertCommand SQL 字串、InsertParameters 集合中指定的任何參數,以及 values 集合中指定的值,執行插入作業。Performs an insert operation using the InsertCommand SQL string, any parameters that are specified in the InsertParameters collection, and the values that are in the specified values collection.

ExecuteSelect(DataSourceSelectArguments)

使用 SelectCommand SQL 字串和 SelectParameters 集合中的任何參數,從基礎資料庫擷取資料。Retrieves data from the underlying database using the SelectCommand SQL string and any parameters that are in the SelectParameters collection.

ExecuteUpdate(IDictionary, IDictionary, IDictionary)

使用 UpdateCommand SQL 字串、UpdateParameters 集合中指定的任何參數,以及 keysvaluesoldValues 集合中指定的值,執行更新作業。Performs an update operation using the UpdateCommand SQL string, any parameters that are in the UpdateParameters collection, and the values that are in the specified keys, values, and oldValues collections.

GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(繼承來源 Object)
GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(繼承來源 Object)
Insert(IDictionary)

使用 InsertCommand SQL 字串、InsertParameters 集合中指定的任何參數,以及 values 集合中指定的值,執行插入作業。Performs an insert operation using the InsertCommand SQL string, any parameters that are specified in the InsertParameters collection, and the values that are in the specified values collection.

Insert(IDictionary, DataSourceViewOperationCallback)

DataSourceView 物件表示的資料清單上,執行非同步插入作業。Performs an asynchronous insert operation on the list of data that the DataSourceView object represents.

(繼承來源 DataSourceView)
LoadViewState(Object)

還原資料來源檢視之先前儲存的檢視狀態。Restores the previously saved view state for the data source view.

MemberwiseClone()

建立目前 Object 的淺層複製。Creates a shallow copy of the current Object.

(繼承來源 Object)
OnDataSourceViewChanged(EventArgs)

引發 DataSourceViewChanged 事件。Raises the DataSourceViewChanged event.

(繼承來源 DataSourceView)
OnDeleted(SqlDataSourceStatusEventArgs)

Deleted 控制項完成刪除作業之後,引發 SqlDataSource 事件。Raises the Deleted event after the SqlDataSource control has completed a delete operation.

OnDeleting(SqlDataSourceCommandEventArgs)

Deleting 控制項嘗試刪除作業之前,引發 SqlDataSource 事件。Raises the Deleting event before the SqlDataSource control attempts a delete operation.

OnFiltering(SqlDataSourceFilteringEventArgs)

Filtering 控制項篩選選取作業的結果之前,引發 SqlDataSource 事件。Raises the Filtering event before the SqlDataSource control filters the results of a select operation.

OnInserted(SqlDataSourceStatusEventArgs)

Inserted 控制項完成插入作業之後,引發 SqlDataSource 事件。Raises the Inserted event after the SqlDataSource control has completed an insert operation.

OnInserting(SqlDataSourceCommandEventArgs)

Inserting 控制項嘗試插入作業之前,引發 SqlDataSource 事件。Raises the Inserting event before the SqlDataSource control attempts an insert operation.

OnSelected(SqlDataSourceStatusEventArgs)

Selected 控制項完成資料擷取作業之後,引發 SqlDataSource 事件。Raises the Selected event after the SqlDataSource control has completed a data retrieval operation.

OnSelecting(SqlDataSourceSelectingEventArgs)

Selecting 控制項嘗試資料擷取作業之前,引發 SqlDataSource 事件。Raises the Selecting event before the SqlDataSource control attempts a data retrieval operation.

OnUpdated(SqlDataSourceStatusEventArgs)

Updated 控制項完成更新作業之後,引發 SqlDataSource 事件。Raises the Updated event after the SqlDataSource control has completed an update operation.

OnUpdating(SqlDataSourceCommandEventArgs)

Updating 控制項嘗試更新作業之前,引發 SqlDataSource 事件。Raises the Updating event before the SqlDataSource control attempts an update operation.

RaiseUnsupportedCapabilityError(DataSourceCapabilities)

比較 ExecuteSelect(DataSourceSelectArguments) 作業所要求的功能與檢視所支援且由 RaiseUnsupportedCapabilitiesError(DataSourceView) 方法呼叫的那些功能。Compares the capabilities that are requested for an ExecuteSelect(DataSourceSelectArguments) operation against those that the view supports and is called by the RaiseUnsupportedCapabilitiesError(DataSourceView) method.

SaveViewState()

儲存自頁面回傳至伺服器以來,SqlDataSourceView 控制項檢視狀態的變更。Saves the changes to the view state for the SqlDataSourceView control since the time that the page was posted back to the server.

Select(DataSourceSelectArguments)

使用 SelectCommand SQL 字串和 SelectParameters 集合中的任何參數,從基礎資料庫擷取資料。Retrieves data from the underlying database using the SelectCommand SQL string and any parameters that are in the SelectParameters collection.

Select(DataSourceSelectArguments, DataSourceViewSelectCallback)

從基礎資料儲存區非同步取得資料清單。Gets a list of data asynchronously from the underlying data storage.

(繼承來源 DataSourceView)
ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(繼承來源 Object)
TrackViewState()

SqlDataSourceView 追蹤其檢視狀態變更,以將變更儲存在控制項的 StateBag 物件中,並持續為相同頁面的其他要求進行追蹤。Causes the SqlDataSourceView object to track changes to its view state so that the changes can be stored in the StateBag object for the control and persisted across requests for the same page.

Update(IDictionary, IDictionary, IDictionary)

使用 UpdateCommand SQL 字串、UpdateParameters 集合中指定的任何參數,以及 keysvaluesoldValues 集合中指定的值,執行更新作業。Performs an update operation using the UpdateCommand SQL string, any parameters that are in the UpdateParameters collection, and the values that are in the specified keys, values, and oldValues collections.

Update(IDictionary, IDictionary, IDictionary, DataSourceViewOperationCallback)

DataSourceView 物件表示的資料清單上,執行非同步更新作業。Performs an asynchronous update operation on the list of data that the DataSourceView object represents.

(繼承來源 DataSourceView)

事件

DataSourceViewChanged

當資料來源檢視已變更時發生。Occurs when the data source view has changed.

(繼承來源 DataSourceView)
Deleted

發生於刪除作業已經完成時。Occurs when a delete operation has completed.

Deleting

在刪除作業之前發生。Occurs before a delete operation.

Filtering

在篩選作業之前發生。Occurs before a filter operation.

Inserted

發生於插入作業已經完成時。Occurs when an insert operation has completed.

Inserting

在插入作業之前發生。Occurs before an insert operation.

Selected

發生於資料擷取作業已經完成時。Occurs when a data retrieval operation has completed.

Selecting

在資料擷取作業之前發生。Occurs before a data retrieval operation.

Updated

發生於更新作業已經完成時。Occurs when an update operation has completed.

Updating

在更新作業之前發生。Occurs before an update operation.

明確介面實作

IStateManager.IsTrackingViewState

如需這個成員的說明,請參閱 IsTrackingViewStateFor a description of this member, see IsTrackingViewState.

IStateManager.LoadViewState(Object)

如需這個成員的說明,請參閱 LoadViewState(Object)For a description of this member, see LoadViewState(Object).

IStateManager.SaveViewState()

如需這個成員的說明,請參閱 SaveViewState()For a description of this member, see SaveViewState().

IStateManager.TrackViewState()

如需這個成員的說明,請參閱 TrackViewState()For a description of this member, see TrackViewState().

適用於

另請參閱