Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
Previous Versions
.NET Framework 2.0
SqlDataSource Class
 DataSourceMode Property
This page is specific to
Microsoft Visual Studio 2005/.NET Framework 2.0

Other versions are also available for the following:
.NET Framework Class Library
SqlDataSource.DataSourceMode Property

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

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)

Visual Basic (Declaration)
Public Property DataSourceMode As SqlDataSourceMode
Visual Basic (Usage)
Dim instance As SqlDataSource
Dim value As SqlDataSourceMode

value = instance.DataSourceMode

instance.DataSourceMode = value
C#
public SqlDataSourceMode DataSourceMode { get; set; }
C++
public:
property SqlDataSourceMode DataSourceMode {
    SqlDataSourceMode get ();
    void set (SqlDataSourceMode value);
}
J#
/** @property */
public SqlDataSourceMode get_DataSourceMode ()

/** @property */
public void set_DataSourceMode (SqlDataSourceMode value)
JScript
public function get DataSourceMode () : SqlDataSourceMode

public function set DataSourceMode (value : SqlDataSourceMode)

Property Value

One of the SqlDataSourceMode values. The default is the DataSet value.
Exception typeCondition

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.

Visual Basic
<%@ Page language="VB" %>

<!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>
C#
<%@ 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>
J#
<!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>

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
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker