SqlDataSourceMode 枚举

定义

指定 SqlDataSourceAccessDataSource 控件是以 IDataReader 还是 DataSet 形式检索数据。Specifies 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

IDataReader 形式从基础数据存储区检索数据Retrieves 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控件的属性设置为, 以便DataReader在将 SQL Server 数据库中的项的简单列表检索到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>

注解

枚举由SqlDataSource Select和控件用于说明调用方法时数据源控件使用的数据检索模式。AccessDataSource 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.

适用于

另请参阅