ערוך

שתף באמצעות


SessionParameter Constructors

Definition

Initializes a new instance of the SessionParameter class.

Overloads

SessionParameter()

Initializes a new unnamed instance of the SessionParameter class.

SessionParameter(SessionParameter)

Initializes a new instance of the SessionParameter class with the values of the instance specified by the original parameter.

SessionParameter(String, String)

Initializes a new named instance of the SessionParameter class, using the specified string to identify which session state name/value pair to bind to.

SessionParameter(String, DbType, String)

Initializes a new instance of the SessionParameter class, by using the specified name and type, and binding the parameter to the specified session state name/value pair. This constructor is for database types.

SessionParameter(String, TypeCode, String)

Initializes a new named and strongly typed instance of the SessionParameter class, using the specified string to identify which session state name/value pair to bind to.

SessionParameter()

Initializes a new unnamed instance of the SessionParameter class.

public:
 SessionParameter();
public SessionParameter ();
Public Sub New ()

Examples

The following code example demonstrates how to create a default instance of the SessionParameter class with the SessionParameter constructor.

// In this example, the session parameter "empid" is set
// after the employee successfully logs in.
SessionParameter empid = new SessionParameter();
empid.Name = "empid";
empid.Type = TypeCode.Int32;
empid.SessionField = "empid";
' In this example, the session parameter "empid" is set
' after the employee successfully logs in.
Dim empid As New SessionParameter()
empid.Name = "empid"
empid.Type = TypeCode.Int32
empid.SessionField = "empid"

Remarks

A SessionParameter object created with the SessionParameter constructor is initialized with default values for all its properties. The SessionField property is initialized to String.Empty. Additionally, the Name property is initialized to String.Empty, the Type property is initialized to TypeCode.Object, the Direction property is initialized to ParameterDirection.Input, and the DefaultValue property is initialized to null.

Applies to

SessionParameter(SessionParameter)

Initializes a new instance of the SessionParameter class with the values of the instance specified by the original parameter.

protected:
 SessionParameter(System::Web::UI::WebControls::SessionParameter ^ original);
protected SessionParameter (System.Web.UI.WebControls.SessionParameter original);
new System.Web.UI.WebControls.SessionParameter : System.Web.UI.WebControls.SessionParameter -> System.Web.UI.WebControls.SessionParameter
Protected Sub New (original As SessionParameter)

Parameters

original
SessionParameter

A SessionParameter from which the current instance is initialized.

Remarks

The SessionParameter(SessionParameter) constructor is a Protected copy constructor used to clone a SessionParameter instance. The values of the SessionParameter object, including the SessionField, Name, and Type properties, are all transferred to the new instance.

See also

Applies to

SessionParameter(String, String)

Initializes a new named instance of the SessionParameter class, using the specified string to identify which session state name/value pair to bind to.

public:
 SessionParameter(System::String ^ name, System::String ^ sessionField);
public SessionParameter (string name, string sessionField);
new System.Web.UI.WebControls.SessionParameter : string * string -> System.Web.UI.WebControls.SessionParameter
Public Sub New (name As String, sessionField As String)

Parameters

name
String

The name of the parameter.

sessionField
String

The name of the HttpSessionState name/value pair that the parameter object is bound to. The default is Empty.

Remarks

The Type and Direction properties are initialized with default values.

See also

Applies to

SessionParameter(String, DbType, String)

Initializes a new instance of the SessionParameter class, by using the specified name and type, and binding the parameter to the specified session state name/value pair. This constructor is for database types.

public:
 SessionParameter(System::String ^ name, System::Data::DbType dbType, System::String ^ sessionField);
public SessionParameter (string name, System.Data.DbType dbType, string sessionField);
new System.Web.UI.WebControls.SessionParameter : string * System.Data.DbType * string -> System.Web.UI.WebControls.SessionParameter
Public Sub New (name As String, dbType As DbType, sessionField As String)

Parameters

name
String

The name of the parameter.

dbType
DbType

The database type that the parameter represents.

sessionField
String

The name of the HttpSessionState name/value pair that the parameter object is bound to. The default is Empty.

Remarks

The Direction and ConvertEmptyStringToNull properties are initialized with default values.

Applies to

SessionParameter(String, TypeCode, String)

Initializes a new named and strongly typed instance of the SessionParameter class, using the specified string to identify which session state name/value pair to bind to.

public:
 SessionParameter(System::String ^ name, TypeCode type, System::String ^ sessionField);
public SessionParameter (string name, TypeCode type, string sessionField);
new System.Web.UI.WebControls.SessionParameter : string * TypeCode * string -> System.Web.UI.WebControls.SessionParameter
Public Sub New (name As String, type As TypeCode, sessionField As String)

Parameters

name
String

The name of the parameter.

type
TypeCode

The type that the parameter represents. The default is Object.

sessionField
String

The name of the HttpSessionState name/value pair that the parameter object is bound to. The default is Empty.

Examples

The following code example demonstrates how to use the SessionParameter constructor to create a SessionParameter object and use it with a SqlDataSource control to display data in a DataGrid control.

<%@ 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">
private void Page_Load(object sender, System.EventArgs e)
{
    SqlDataSource OdbcToSql = new SqlDataSource();

    // Connect to SQL Server using an ODBC DSN.
    OdbcToSql.ProviderName= "System.Data.Odbc";
    OdbcToSql.ConnectionString = "dsn=MyOdbcDsn;";

    // Use an ODBC parameterized query syntax.
    OdbcToSql.SelectCommand = "SELECT EmployeeID FROM Employees " +
                              " WHERE Country = ? AND ReportsTo = ?";

    // The country parameter has no default value, so be sure to set
    // a Session variable named "country" to "UK" or "USA".
    SessionParameter country =
        new SessionParameter("country",TypeCode.String,"country");

    SessionParameter reportsTo =
        new SessionParameter("report",TypeCode.Int32,"report");
    reportsTo.DefaultValue = "2";

    OdbcToSql.SelectParameters.Add(country);
    OdbcToSql.SelectParameters.Add(reportsTo);

    // Add the DataSourceControl to the page's Controls collection.
    Page.Controls.Add(OdbcToSql);

    DataGrid1.DataSource = OdbcToSql;
    DataGrid1.DataBind();
}

</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
        <form id="Form1" method="post" runat="server">
            <asp:DataGrid
                id="DataGrid1"
                style="Z-INDEX: 101; LEFT: 56px; POSITION: absolute; TOP: 56px"
                runat="server" />
        </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)

    Dim OdbcToSql As New SqlDataSource()

    ' Connect to SQL Server using an ODBC DSN.
    OdbcToSql.ProviderName= "System.Data.Odbc"
    OdbcToSql.ConnectionString = "dsn=MyOdbcDsn;"

    ' Use an ODBC parameterized query syntax.
    OdbcToSql.SelectCommand = "SELECT EmployeeID FROM Employees " & _
                              " WHERE Country = ? AND ReportsTo = ?"

    ' The country parameter has no default value, so be sure to set
    ' a Session variable named "country" to "UK" or "USA".
    Dim country As SessionParameter
    country = New SessionParameter("country",TypeCode.String,"country")

    Dim reportsTo As SessionParameter
    reportsTo = New SessionParameter("report",TypeCode.Int32,"report")
    reportsTo.DefaultValue = "2"

    OdbcToSql.SelectParameters.Add(country)
    OdbcToSql.SelectParameters.Add(reportsTo)

    ' Add the DataSourceControl to the page's Controls collection.
    Page.Controls.Add(OdbcToSql)

    DataGrid1.DataSource = OdbcToSql
    DataGrid1.DataBind()

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" method="post" runat="server">
      <asp:DataGrid
          id="DataGrid1"
          style="Z-INDEX: 101; LEFT: 56px; POSITION: absolute; TOP: 56px"
          runat="server" />
    </form>
  </body>
</html>

Remarks

The Direction and ConvertEmptyStringToNull properties are initialized with default values.

See also

Applies to