Share via


SqlCeParameter Constructor (String, Object)

Initializes a new instance of the SqlCeParameter class with the parameter name and the value of the new SqlCeParameter.

Namespace: System.Data.SqlServerCe
Assembly: System.Data.SqlServerCe (in system.data.sqlserverce.dll)

Syntax

'Declaration
Public Sub New ( _
    name As String, _
    value As Object _
)
public SqlCeParameter (
    string name,
    Object value
)
public:
SqlCeParameter (
    String^ name, 
    Object^ value
)
public SqlCeParameter (
    String name, 
    Object value
)
public function SqlCeParameter (
    name : String, 
    value : Object
)

Parameters

  • name
    The name of the parameter to map.

Exceptions

Exception type Condition
ArgumentException

The value supplied for the parameter cannot be converted to a database type supported by SQL Server Compact 3.5 SP1.

Remarks

When you specify an Object in the value parameter, the SqlDbType is inferred from the .NET Framework type of the Object.

Use caution when using this overload of the SqlCeParameter constructor to specify integer parameter values. Because this overload takes a value of type Object, you must convert the integral value to an Object type when the value is zero, as the following C# example demonstrates.

 Parameter = new SqlParameter("@pname", Convert.ToInt32(0));

If you do not perform this conversion, the compiler will assume you are attempting to call the SqlParameter (string, SqlDbType) constructor overload.

Example

The following example creates a SqlCeParameter.

' Create and assign a value to a parameter of SqlDbType.NChar (String).
Dim p2 As New SqlCeParameter("@Description", "Soft drinks, coffees, teas, beers, and ales")

' Create and assign a value to a parameter of SqlDbType.Int (Int32).
Dim p1 As New SqlCeParameter("@CategoryID", 1)
p1.SqlDbType = SqlDbType.Int
// Create and assign a value to a parameter of SqlDbType.NChar (String).
SqlCeParameter p2 = new SqlCeParameter("@Description", "Soft drinks, coffees, teas, beers, and ales");

// Create and assign a value to a parameter of SqlDbType.Int (Int32).
SqlCeParameter p1 = new SqlCeParameter("@CategoryID", 1);
p1.SqlDbType = SqlDbType.Int;

Platforms

Development Platforms

Windows Vista, Windows Mobile 5.0, Windows XP Professional with Service Pack 2 (SP2), Windows Server 2003, Windows Mobile 2003 for Pocket PC, Windows CE 5.0
Version Information
.NET Framework and NET Compact Framework
Supported in 3.5
.NET Framework
Supported in 3.0
.NET Compact Framework and .Net Framework
Supported in 2.0

See Also

Reference

SqlCeParameter Class
SqlCeParameter Members
System.Data.SqlServerCe Namespace