SqlDataSourceMode SqlDataSourceMode SqlDataSourceMode SqlDataSourceMode Enum

Definizione

Specifica se un controllo SqlDataSource o AccessDataSource recupera i dati come IDataReader o 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
Ereditarietà
SqlDataSourceModeSqlDataSourceModeSqlDataSourceModeSqlDataSourceMode

Campi

DataReader DataReader DataReader DataReader 0

Recupera i dati dall'archivio dati sottostante come una classe IDataReader.Retrieves data from the underlying data storage as an IDataReader

DataSet DataSet DataSet DataSet 1

Recupera i dati dall'archivio dati sottostante in una struttura DataSet.Retrieves data from the underlying data storage into a DataSet structure.

Esempi

Nell'esempio seguente viene illustrato come impostare la DataSourceMode proprietà di un SqlDataSource controllo su DataReader quando si recupera un semplice elenco di elementi da un database di SQL Server in ListBox un controllo.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>

Nell'esempio seguente viene illustrato come impostare la SqlDataSource.DataSourceMode proprietà su DataSet quando si recupera un set di dati in un GridView controllo in cui è abilitato l'ordinamento.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>

Commenti

L' SqlDataSourceMode enumerazione viene utilizzata SqlDataSource dai controlli e AccessDataSource per descrivere la modalità di recupero dei dati utilizzata dal controllo origine dati quando viene chiamato Select il metodo.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. Quando la DataSourceMode proprietà è impostata su DataSet, i dati vengono caricati in DataSet una struttura.When the DataSourceMode property is set to DataSet, data is loaded into a DataSet structure. Questo consente scenari in GridView cui i controlli dell'interfaccia utente, ad esempio offrono funzionalità di ordinamento e paging.This enables scenarios where user interface controls such as GridView offer sorting and paging capabilities. Quando la DataSourceMode proprietà è impostata su DataReader, i dati vengono recuperati IDataReader da un oggetto, che è un cursore di sola lettura e di sola trasmissione.When the DataSourceMode property is set to DataReader, data is retrieved by an IDataReader object, which is a read-only, forward-only cursor.

L' SqlDataSourceMode enumerazione viene utilizzata solo per descrivere il modo Select in cui il comando recupera i dati; non ha alcun effetto SqlDataSource sulle altre operazioni eseguite dal Insertcontrollo, ad Deleteesempio, Updateo.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.

Si applica a

Vedi anche