Export (0) Print
Expand All
Expand Minimize

SqlDataSourceMode Enumeration

Note: This enumeration is new in the .NET Framework version 2.0.

Specifies whether a SqlDataSource or AccessDataSource control retrieves data as a IDataReader or DataSet.

Namespace: System.Web.UI.WebControls
Assembly: System.Web (in system.web.dll)

public enum SqlDataSourceMode
public enum SqlDataSourceMode
public enum SqlDataSourceMode

 Member nameDescription
DataReaderRetrieves data from the underlying data storage as an IDataReader 
DataSetRetrieves data from the underlying data storage into a DataSet structure. 

The 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. When the DataSourceMode property is set to DataSet, data is loaded into a DataSet structure. This enables scenarios where user interface controls such as GridView offer sorting and paging capabilities. When the DataSourceMode property is set to DataReader, data is retrieved by an IDataReader object, which is a read-only, forward-only cursor.

The 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.

TopicLocation
How to: Connect to an ODBC Database Using the SqlDataSource ControlBuilding ASP .NET Web Applications
How to: Access SQL Server as a Local UserBuilding ASP .NET Web Applications
How to: Connect to an ODBC Database Using the SqlDataSource ControlBuilding ASP .NET Web Applications
How to: Access SQL Server as a Local UserBuilding ASP .NET Web Applications
How to: Connect to an ODBC Database Using the SqlDataSource Control (Visual Studio)Building ASP .NET Web Applications in Visual Studio

The following code example demonstrates how to set the DataSourceMode of a SqlDataSource control to DataReader when retrieving a simple list of items from a SQL Server database into a ListBox control.

<%@ Page language="CS" %>

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

<HTML>
  <BODY>
    <FORM 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>

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

<HTML>
  <BODY>
    <FORM runat="server">
      <asp:SqlDataSource
          id="SqlDataSource1"
          runat="server"
          DataSourceMode="DataReader"
          ConnectionString="Data Source=localhost;Integrated Security=SSPI;Initial Catalog=Northwind;"
          SelectCommand="SELECT LastName FROM Employees">
      </asp:SqlDataSource>

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

    </FORM>
  </BODY>
</HTML>

The following code example demonstrates how to set the DataSourceMode 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>
  <BODY>
    <FORM 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>
  <BODY>
    <FORM runat="server">

      <asp:SqlDataSource
          id="SqlDataSource1"
          runat="server"
          DataSourceMode="DataSet"
          ConnectionString="Data Source=localhost;Integrated Security=SSPI;Initial Catalog=Northwind;"
          SelectCommand="SELECT FirstName, LastName, Title FROM Employees">
      </asp:SqlDataSource>

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

    </FORM>
  </BODY>
</HTML>

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0

Community Additions

ADD
Show:
© 2014 Microsoft