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)

public SqlCeParameter(
	string name,
	Object value
)

Parameters

name
Type: System.String
The name of the parameter to map.
value
Type: System.Object
The value of the new SqlCeParameter object.

ExceptionCondition
ArgumentException

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

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.

The following example creates a SqlCeParameter.

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


Show: