Export (0) Print
Expand All

SqlParameterCollection.Add Method

Adds a SqlParameter to the SqlParameterCollection.

Overload List

Adds the specified SqlParameter object to the SqlParameterCollection.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Overridable Function Add(Object) As Integer Implements IList.Add
[C#] public virtual int Add(object);
[C++] public: virtual int Add(Object*);
[JScript] public function Add(Object) : int;

Adds the specified SqlParameter object to the SqlParameterCollection.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Function Add(SqlParameter) As SqlParameter
[C#] public SqlParameter Add(SqlParameter);
[C++] public: SqlParameter* Add(SqlParameter*);
[JScript] public function Add(SqlParameter) : SqlParameter;

Adds a SqlParameter to the SqlParameterCollection given the specified parameter name and value.

Supported by the .NET Compact Framework.

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

Adds a SqlParameter to the SqlParameterCollection given the parameter name and the data type.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Function Add(String, SqlDbType) As SqlParameter
[C#] public SqlParameter Add(string, SqlDbType);
[C++] public: SqlParameter* Add(String*, SqlDbType);
[JScript] public function Add(String, SqlDbType) : SqlParameter;

Adds a SqlParameter to the SqlParameterCollection with the parameter name, the data type, and the column length.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Function Add(String, SqlDbType, Integer) As SqlParameter
[C#] public SqlParameter Add(string, SqlDbType, int);
[C++] public: SqlParameter* Add(String*, SqlDbType, int);
[JScript] public function Add(String, SqlDbType, int) : SqlParameter;

Adds a SqlParameter to the SqlParameterCollection with the parameter name, the data type, the column length, and the source column name.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Function Add(String, SqlDbType, Integer, String) As SqlParameter
[C#] public SqlParameter Add(string, SqlDbType, int, string);
[C++] public: SqlParameter* Add(String*, SqlDbType, int, String*);
[JScript] public function Add(String, SqlDbType, int, String) : SqlParameter;

Example

[Visual Basic, C#, C++] Note   This example shows how to use one of the overloaded versions of Add. For other examples that might be available, see the individual overload topics.
[Visual Basic] 
Public Sub AddSqlParameter(cmd As SqlCommand) 
  Dim p1 As SqlParameter = cmd.Parameters.Add("@Description", SqlDbType.NVarChar, 16, "Description")
End Sub

[C#] 
public void AddSqlParameter(SqlCommand cmd) 
{
  SqlParameter p1 = cmd.Parameters.Add("@Description", SqlDbType.NVarChar, 16, "Description");
}

[C++] 
public:
    void AddSqlParameter(SqlCommand* cmd)
    {
        SqlParameter* p1 = cmd->Parameters->Add(S"@Description", SqlDbType::NVarChar, 16, S"Description");
    };

[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.

See Also

SqlParameterCollection Class | SqlParameterCollection Members | System.Data.SqlClient Namespace

Show:
© 2014 Microsoft