Condividi tramite


SqlCeParameterCollection.Add Method (String, Object)

Note: This namespace, class, or member is supported only in version 1.1 of the .NET Framework.

Adds a SqlCeParameter to the SqlCeParameterCollection given the parameter name and value.

  [Visual Basic]
  Overloads Public Function Add( _
   ByVal 
  parameterName
   As String, _
   ByVal value As Object _
) As SqlCeParameter
[C#]
public SqlCeParameter Add(string parameterName,object value
);
[C++]
public: SqlCeParameter* Add(String* parameterName,Object* value
);
[JScript]
public function Add(
   parameterName : String,
 value : Object) : SqlCeParameter;

Parameters

  • parameterName
    The name of the parameter.
  • value
    The Object value of the SqlCeParameter to add to the collection.

Return Value

A reference to the new SqlCeParameter object.

Exceptions

Exception Type Condition
InvalidCastException The object supplied as the value parameter cannot be converted to a string. This can happen if the object is not a primative type, SqlDbType or byte array.

Remarks

The SqlDbType of the new SqlCeParameter object is not inferred from the .NET Compact Framework type of the value parameter. The Value property of the new SqlCeParameter object is set to the string obtained from converting value parameter and the SqlDbType is set to SqlDbType.NChar.

If you want to explicly set the SqlDbType of the parameter when it is created, you should use one of the other overloaded Add methods.

Example

[Visual Basic, C#, C++] The following example adds new element to a SqlCeParameterCollection. It assumes that a SqlCeCommand has already been created.

  [Visual Basic] 
Public Sub AddSqlCeParameter(ByVal cmd As SqlCeCommand)
    cmd.Parameters.Add("@Description", "Beverages")
End Sub

[C#] 
public void AddSqlCeParameter(SqlCeCommand cmd) {
    cmd.Parameters.Add("@Description", "Beverages");
}

[C++] 
public:
    void AddSqlCeParameter(SqlCeCommand* cmd)
    {
        cmd->Parameters->Add(S"@Description", S"Beverages");
    };

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: .NET Compact Framework

.NET Framework Security:

See Also

SqlCeParameterCollection Class | SqlCeParameterCollection Members | System.Data.SqlServerCe Namespace | SqlCeParameterCollection.Add Overload List

Syntax based on .NET Framework version 1.1.
Documentation version 1.1.1.

Send comments on this topic.

© Microsoft Corporation. All rights reserved.