ParameterCollection.Add Metodo

Definizione

Aggiunge un Parameter oggetto all'insieme.

Overload

Nome Descrizione
Add(Parameter)

Accoda l'oggetto specificato Parameter alla fine dell'insieme.

Add(String, String)

Crea un Parameter oggetto con il nome e il valore predefinito specificati e lo aggiunge alla fine della raccolta.

Add(String, DbType, String)

Crea un Parameter oggetto con il nome, il tipo di database e il valore predefinito specificati e lo aggiunge alla fine della raccolta.

Add(String, TypeCode, String)

Crea un Parameter oggetto con il nome, TypeCodee il valore predefinito specificati e lo aggiunge alla fine della raccolta.

Add(Parameter)

Accoda l'oggetto specificato Parameter alla fine dell'insieme.

public:
 int Add(System::Web::UI::WebControls::Parameter ^ parameter);
public int Add(System.Web.UI.WebControls.Parameter parameter);
member this.Add : System.Web.UI.WebControls.Parameter -> int
Public Function Add (parameter As Parameter) As Integer

Parametri

parameter
Parameter

Oggetto Parameter da accodare all'insieme.

Valori restituiti

Valore di indice dell'elemento aggiunto.

Esempio

Nell'esempio di codice seguente viene illustrato come utilizzare un controllo /> . L'oggetto FormParameter viene aggiunto all'insieme SelectParameters utilizzando il Add(Parameter) metodo .

Importante

In questo esempio è presente una casella di testo che accetta l'input dell'utente, che rappresenta una potenziale minaccia per la sicurezza. Per impostazione predefinita, ASP.NET pagine Web verificare che l'input dell'utente non includa elementi SCRIPT o HTML. Per altre informazioni, vedere Cenni preliminari sugli exploit di script.

<%@Page  Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

void Page_Load(Object sender, EventArgs e){

  // You can add a FormParameter to the AccessDataSource control's
  // SelectParameters collection programmatically.
  AccessDataSource1.SelectParameters.Clear();

  // Security Note: The AccessDataSource uses a FormParameter,
  // Security Note: which does not perform validation of input from the client.
  // Security Note: To validate the value of the FormParameter,
  // Security Note: handle the Selecting event.

  FormParameter formParam = new FormParameter("lastname","LastNameBox");
  formParam.Type=TypeCode.String;
  AccessDataSource1.SelectParameters.Add(formParam);
}

</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
    <form id="form1" runat="server">

      <asp:accessdatasource
          id="AccessDataSource1"
          runat="server"
          datasourcemode="DataSet"
          datafile="Northwind.mdb"
          selectcommand="SELECT OrderID,CustomerID,OrderDate,RequiredDate,ShippedDate
                         FROM Orders WHERE EmployeeID =
                         (SELECT EmployeeID FROM Employees WHERE LastName = @lastname)">
      </asp:accessdatasource>

      <br />Enter the name "Davolio" or "King" in the text box and click the button.

      <br />
      <asp:textbox
        id="LastNameBox"
        runat="server" />

      <br />
      <asp:button
        id="Button1"
        runat="server"
        text="Get Records" />

      <br />
      <asp:gridview
          id="GridView1"
          runat="server"
          allowsorting="True"
          datasourceid="AccessDataSource1">
      </asp:gridview>

    </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">

<script runat="server">

Private Sub Page_Load(sender As Object, e As EventArgs)

  ' You can add a FormParameter to the AccessDataSource control's
  ' SelectParameters collection programmatically.
  AccessDataSource1.SelectParameters.Clear()

  ' Security Note: The AccessDataSource uses a FormParameter,
  ' Security Note: which does not perform validation of input from the client.
  ' Security Note: To validate the value of the FormParameter,
  ' Security Note: handle the Selecting event.

  Dim formParam As New FormParameter("lastname","LastNameBox")
  formParam.Type=TypeCode.String
  AccessDataSource1.SelectParameters.Add(formParam)
End Sub ' Page_Load

</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
    <form id="form1" runat="server">

      <asp:accessdatasource
          id="AccessDataSource1"
          runat="server"
          datasourcemode="DataSet"
          datafile="Northwind.mdb"
          selectcommand="SELECT OrderID,CustomerID,OrderDate,RequiredDate,ShippedDate
                         FROM Orders WHERE EmployeeID =
                         (SELECT EmployeeID FROM Employees WHERE LastName = @lastname)">
      </asp:accessdatasource>

      <br />Enter the name "Davolio" or "King" in the text box and click the button.

      <br />
      <asp:textbox
        id="LastNameBox"
        runat="server" />

      <br />
      <asp:button
        id="Button1"
        runat="server"
        text="Get Records" />

      <br />
      <asp:gridview
          id="GridView1"
          runat="server"
          allowsorting="True"
          datasourceid="AccessDataSource1">
      </asp:gridview>

    </form>
  </body>
</html>

Commenti

Utilizzare il Add(Parameter) metodo per aggiungere un Parameter oggetto alla fine dell'insieme. Questa implementazione del metodo accetta l'oggetto Parameter specificato dal param parametro e lo aggiunge alla raccolta.

Vedi anche

Si applica a

Add(String, String)

Crea un Parameter oggetto con il nome e il valore predefinito specificati e lo aggiunge alla fine della raccolta.

public:
 int Add(System::String ^ name, System::String ^ value);
public int Add(string name, string value);
member this.Add : string * string -> int
Public Function Add (name As String, value As String) As Integer

Parametri

name
String

Nome del parametro.

value
String

Stringa che funge da valore predefinito per il parametro .

Valori restituiti

Valore di indice dell'elemento aggiunto.

Commenti

Utilizzare il Add(String, String) metodo per creare e aggiungere un Parameter oggetto con un valore predefinito alla fine della raccolta. Questa implementazione del metodo crea l'oggetto Parameter usando rispettivamente il nome e il valore predefinito specificati dai name parametri e value e lo aggiunge all'insieme.

Vedi anche

Si applica a

Add(String, DbType, String)

Crea un Parameter oggetto con il nome, il tipo di database e il valore predefinito specificati e lo aggiunge alla fine della raccolta.

public:
 int Add(System::String ^ name, System::Data::DbType dbType, System::String ^ value);
public int Add(string name, System.Data.DbType dbType, string value);
member this.Add : string * System.Data.DbType * string -> int
Public Function Add (name As String, dbType As DbType, value As String) As Integer

Parametri

name
String

Nome del parametro.

dbType
DbType

Tipo di database del parametro.

value
String

Il valore predefinito per il parametro.

Valori restituiti

Valore di indice dell'elemento aggiunto.

Commenti

Questo metodo è per i tipi di database. Usare il Add(String, TypeCode, String) metodo per i tipi CLR.

Si applica a

Add(String, TypeCode, String)

Crea un Parameter oggetto con il nome, TypeCodee il valore predefinito specificati e lo aggiunge alla fine della raccolta.

public:
 int Add(System::String ^ name, TypeCode type, System::String ^ value);
public int Add(string name, TypeCode type, string value);
member this.Add : string * TypeCode * string -> int
Public Function Add (name As String, type As TypeCode, value As String) As Integer

Parametri

name
String

Nome del parametro.

type
TypeCode

Il tipo di parametro.

value
String

Il valore predefinito per il parametro.

Valori restituiti

Valore di indice dell'elemento aggiunto.

Commenti

Utilizzare il Add(String, TypeCode, String) metodo per creare e aggiungere un oggetto fortemente tipizzato Parameter con un valore predefinito alla fine dell'insieme. Questa implementazione del metodo crea l'oggetto Parameter usando rispettivamente il nome, il tipo e il valore specificati dai nameparametri , type e value e lo aggiunge all'insieme.

Vedi anche

Si applica a