SqlDataSourceMode Wyliczenie

Definicja

Określa, czy kontrolka SqlDataSource pobiera AccessDataSource dane jako element IDataReader lub DataSet.

public enum class SqlDataSourceMode
public enum SqlDataSourceMode
type SqlDataSourceMode = 
Public Enum SqlDataSourceMode
Dziedziczenie
SqlDataSourceMode

Pola

DataReader 0

Pobiera dane z bazowego magazynu danych jako IDataReader.

DataSet 1

Pobiera dane z bazowego DataSet magazynu danych do struktury.

Przykłady

W poniższym przykładzie pokazano, jak ustawić DataSourceMode właściwość SqlDataSource kontrolki na DataReader podczas pobierania prostej listy elementów z bazy danych SQL Server do kontrolkiListBox.

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

W poniższym przykładzie pokazano, jak ustawić SqlDataSource.DataSourceMode właściwość na DataSet wartość podczas pobierania zestawu danych do GridView kontrolki, która ma włączone sortowanie.

<!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>

Uwagi

Wyliczenie SqlDataSourceMode jest używane przez SqlDataSource kontrolki i AccessDataSource do opisywania trybu pobierania danych używanego przez kontrolkę źródła danych podczas wywoływanej Select metody. Gdy właściwość jest ustawiona DataSourceMode na DataSet, dane są ładowane do DataSet struktury. Umożliwia to scenariusze, w których kontrolki interfejsu użytkownika, takie jak GridView funkcje sortowania ofert i stronicowania. DataSourceMode Gdy właściwość jest ustawiona na DataReaderwartość , dane są pobierane przez IDataReader obiekt, który jest kursorem tylko do odczytu, tylko do odczytu.

Wyliczenie SqlDataSourceMode służy tylko do opisywania Select sposobu pobierania danych przez polecenie; nie ma wpływu na inne operacje SqlDataSource wykonywane przez kontrolkę, takie jak Insert, Updatelub Delete.

Dotyczy

Zobacz też