ParameterCollection.Add Método
Definición
Importante
Parte de la información hace referencia a la versión preliminar del producto, que puede haberse modificado sustancialmente antes de lanzar la versión definitiva. Microsoft no otorga ninguna garantía, explícita o implícita, con respecto a la información proporcionada aquí.
Agrega un Parameter objeto a la colección.
Sobrecargas
| Nombre | Description |
|---|---|
| Add(Parameter) |
Anexa el objeto especificado Parameter al final de la colección. |
| Add(String, String) |
Crea un Parameter objeto con el nombre y el valor predeterminado especificados y lo anexa al final de la colección. |
| Add(String, DbType, String) |
Crea un Parameter objeto con el nombre, el tipo de base de datos y el valor predeterminado especificados y lo agrega al final de la colección. |
| Add(String, TypeCode, String) |
Crea un Parameter objeto con el nombre especificado, TypeCode, y el valor predeterminado, y lo anexa al final de la colección. |
Add(Parameter)
Anexa el objeto especificado Parameter al final de la colección.
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
Parámetros
Devoluciones
Valor de índice del elemento agregado.
Ejemplos
En el ejemplo de código siguiente se muestra cómo usar un control /> de
Importante
Este ejemplo tiene un cuadro de texto que acepta la entrada del usuario, que es una amenaza de seguridad potencial. De forma predeterminada, ASP.NET páginas web validan que la entrada del usuario no incluye elementos HTML ni de script. Para obtener más información, consulte Información general sobre vulnerabilidades de seguridad de 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>
Comentarios
Utilice el Add(Parameter) método para anexar un Parameter objeto al final de la colección. Esta implementación del método toma el Parameter objeto especificado por el param parámetro y lo anexa a la colección.
Consulte también
Se aplica a
Add(String, String)
Crea un Parameter objeto con el nombre y el valor predeterminado especificados y lo anexa al final de la colección.
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
Parámetros
- name
- String
Nombre del parámetro.
- value
- String
Cadena que actúa como valor predeterminado para el parámetro .
Devoluciones
Valor de índice del elemento agregado.
Comentarios
Use el Add(String, String) método para crear y anexar un Parameter objeto con un valor predeterminado al final de la colección. Esta implementación del método crea el Parameter objeto con el nombre y el valor predeterminado especificados por los name parámetros y value , respectivamente, y los anexa a la colección.
Consulte también
Se aplica a
Add(String, DbType, String)
Crea un Parameter objeto con el nombre, el tipo de base de datos y el valor predeterminado especificados y lo agrega al final de la colección.
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
Parámetros
- name
- String
Nombre del parámetro.
- dbType
- DbType
Tipo de base de datos del parámetro .
- value
- String
Valor predeterminado del parámetro.
Devoluciones
Valor de índice del elemento agregado.
Comentarios
Este método es para los tipos de base de datos. Use el Add(String, TypeCode, String) método para los tipos CLR.
Se aplica a
Add(String, TypeCode, String)
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
Parámetros
- name
- String
Nombre del parámetro.
- type
- TypeCode
Tipo del parámetro .
- value
- String
Valor predeterminado del parámetro.
Devoluciones
Valor de índice del elemento agregado.
Comentarios
Use el Add(String, TypeCode, String) método para crear y anexar un objeto fuertemente tipado Parameter con un valor predeterminado al final de la colección. Esta implementación del método crea el Parameter objeto utilizando el nombre, el tipo y el valor especificados por los nameparámetros , type y value , respectivamente, y los anexa a la colección.