Export (0) Print
Expand All

SqlDataSource.DataSourceMode Property

Gets or sets the data retrieval mode that the SqlDataSource control uses to fetch data.

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

public SqlDataSourceMode DataSourceMode { get; set; }
<asp:SqlDataSource DataSourceMode="SqlDataSourceMode" />

Property Value

Type: System.Web.UI.WebControls.SqlDataSourceMode
One of the SqlDataSourceMode values. The default is the DataSet value.

ExceptionCondition
ArgumentOutOfRangeException

The DataSourceMode property is not one of the values defined in the SqlDataSourceMode.

The data retrieval mode identifies how a SqlDataSource control retrieves data from the underlying database.

When the DataSourceMode property is set to the DataSet value, data is loaded into a DataSet object and stored in memory on the server. This enables scenarios where user interface controls, such as GridView, offer sorting, filtering, and paging capabilities.

When the DataSourceMode property is set to the DataReader value, data is retrieved by a IDataReader object, which is a forward-only, read-only cursor. The specific type of the IDataReader object depends on the NET data provider that the SqlDataSource uses, which is identified by the ProviderName property. By default, the SqlDataSource control uses the provider for Microsoft SQL Server, the System.Data.SqlClient, and the data reader is a SqlDataReader object.

If you change the DataSourceMode property, the DataSourceChanged event is raised, causing any controls that are bound to the SqlDataSource to rebind.

The value of the DataSourceMode property is stored in view state.

The following code example demonstrates how to set the DataSourceMode property of the SqlDataSource control to the DataReader value for a scenario with a ListBox control that requires no sorting, paging, nor filtering.

<%@ 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>

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

Show:
© 2014 Microsoft