SqlDataSourceMode 列舉

定義

指定 SqlDataSourceAccessDataSource 控制項取資料做為 IDataReaderDataSetSpecifies whether a SqlDataSource or AccessDataSource control retrieves data as a IDataReader or DataSet.

public enum class SqlDataSourceMode
public enum SqlDataSourceMode
type SqlDataSourceMode = 
Public Enum SqlDataSourceMode
繼承
SqlDataSourceMode

欄位

DataReader 0

從基礎資料儲存區中擷取資料做為 IDataReaderRetrieves data from the underlying data storage as an IDataReader

DataSet 1

從基礎資料儲存區中擷取資料至 DataSet 結構中。Retrieves data from the underlying data storage into a DataSet structure.

範例

下列範例示範如何在將專案的DataSourceMode簡單列表從SqlDataSource SQL Server 資料庫DataReader ListBox抓取至控制項時, 將控制項的屬性設為。The following example demonstrates how to set the DataSourceMode property of a SqlDataSource control to DataReader when retrieving a simple list of items from a SQL Server database into a ListBox control.

<%@ Page language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
    <form id="form1" runat="server">
      <asp:SqlDataSource
          id="SqlDataSource1"
          runat="server"
          DataSourceMode="DataReader"
          ConnectionString="<%$ ConnectionStrings:MyNorthwind%>"
          SelectCommand="SELECT LastName FROM Employees">
      </asp:SqlDataSource>

      <asp:ListBox
          id="ListBox1"
          runat="server"
          DataTextField="LastName"
          DataSourceID="SqlDataSource1">
      </asp:ListBox>

    </form>
  </body>
</html>
<%@ Page language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
    <form id="form1" runat="server">
      <asp:SqlDataSource
          id="SqlDataSource1"
          runat="server"
          DataSourceMode="DataReader"
          ConnectionString="<%$ ConnectionStrings:MyNorthwind%>"
          SelectCommand="SELECT LastName FROM Employees">
      </asp:SqlDataSource>

      <asp:ListBox
          id="ListBox1"
          runat="server"
          DataTextField="LastName"
          DataSourceID="SqlDataSource1">
      </asp:ListBox>

    </form>
  </body>
</html>

下列範例示範如何在將一SqlDataSource.DataSourceMode GridView組資料抓取DataSet至已啟用排序的控制項時, 將屬性設定為。The following example demonstrates how to set the SqlDataSource.DataSourceMode property to DataSet when retrieving a set of data into a GridView control that has sorting enabled.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
    <form id="form1" runat="server">

      <asp:SqlDataSource
          id="SqlDataSource1"
          runat="server"
          DataSourceMode="DataSet"
          ConnectionString="<%$ ConnectionStrings:MyNorthwind%>"
          SelectCommand="SELECT FirstName, LastName, Title FROM Employees">
      </asp:SqlDataSource>

      <asp:GridView
          id="GridView1"
          runat="server"
          AllowSorting="True"
          DataSourceID="SqlDataSource1">
      </asp:GridView>

    </form>
  </body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
    <form id="form1" runat="server">

      <asp:SqlDataSource
          id="SqlDataSource1"
          runat="server"
          DataSourceMode="DataSet"
          ConnectionString="<%$ ConnectionStrings:MyNorthwind%>"
          SelectCommand="SELECT FirstName, LastName, Title FROM Employees">
      </asp:SqlDataSource>

      <asp:GridView
          id="GridView1"
          runat="server"
          AllowSorting="True"
          DataSourceID="SqlDataSource1">
      </asp:GridView>

    </form>
  </body>
</html>

備註

列舉是Select由和控制項AccessDataSource用來描述呼叫方法時, 資料來源控制項所使用的資料抓取模式。 SqlDataSource SqlDataSourceModeThe SqlDataSourceMode enumeration is used by the SqlDataSource and AccessDataSource controls to describe the data retrieval mode that the data source control uses when the Select method is called. 當屬性設定為DataSet時, DataSet資料就會載入結構中。 DataSourceModeWhen the DataSourceMode property is set to DataSet, data is loaded into a DataSet structure. 這會啟用使用者介面控制項的案例, GridView例如供應專案排序和分頁功能。This enables scenarios where user interface controls such as GridView offer sorting and paging capabilities. 當屬性設定為DataReader時, IDataReader物件會抓取資料, 這是唯讀的順向資料指標。 DataSourceModeWhen the DataSourceMode property is set to DataReader, data is retrieved by an IDataReader object, which is a read-only, forward-only cursor.

Insert SqlDataSource Update Delete列舉只會用來描述Select命令如何抓取資料, 它不會影響控制項執行的其他作業, 例如、或。 SqlDataSourceModeThe SqlDataSourceMode enumeration is only used to describe how the Select command retrieves data; it has no effect on other operations the SqlDataSource control performs, such as Insert, Update, or Delete.

適用於

另請參閱