Edit

Share via


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();

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

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

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

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);

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

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

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(string name, string sessionField);

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

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

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(string name, System.Data.DbType dbType, string sessionField);

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

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

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(string name, TypeCode type, string sessionField);

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>

Remarks

The Direction and ConvertEmptyStringToNull properties are initialized with default values.

See also

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1