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 _
)
'Usage
Dim name As String
Dim value As Object
Dim instance As New SqlCeParameter(name, value)
public SqlCeParameter(
string name,
Object value
)
public:
SqlCeParameter(
String^ name,
Object^ value
)
new :
name:string *
value:Object -> SqlCeParameter
public function SqlCeParameter(
name : String,
value : Object
)
Parameters
- name
Type: System. . :: . .String
The name of the parameter to map.
- value
Type: System. . :: . .Object
The value of the new SqlCeParameter object.
Exceptions
Exception | Condition |
---|---|
ArgumentException | The value supplied for the parameter cannot be converted to a database type supported by . |
Remarks
When you specify an Object in the value parameter, the SqlDbType is inferred from the 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.
Examples
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;