This topic has not yet been rated - Rate this topic

SqlParameterCollection.Add Method (String, Object)

NOTE: This method is now obsolete.

Adds the specified SqlParameter object to the SqlParameterCollection.

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

[ObsoleteAttribute("Add(String parameterName, Object value) has been deprecated.  Use AddWithValue(String parameterName, Object value).  http://go.microsoft.com/fwlink/?linkid=14202", false)] 
public SqlParameter Add (
	string parameterName,
	Object value
)
/** @attribute ObsoleteAttribute("Add(String parameterName, Object value) has been deprecated.  Use AddWithValue(String parameterName, Object value).  http://go.microsoft.com/fwlink/?linkid=14202", false) */ 
public SqlParameter Add (
	String parameterName, 
	Object value
)
ObsoleteAttribute("Add(String parameterName, Object value) has been deprecated.  Use AddWithValue(String parameterName, Object value).  http://go.microsoft.com/fwlink/?linkid=14202", false) 
public function Add (
	parameterName : String, 
	value : Object
) : SqlParameter

Parameters

parameterName

The name of the SqlParameter to add to the collection.

value

A Object.

Return Value

The index of the new SqlParameter object. Use caution when you are using this overload of the Add method 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.
parameters.Add("@pname", Convert.ToInt32(0));
If you do not perform this conversion, the compiler assumes that you are trying to call the SqlParameterCollection.Add (string, SqlDbType) overload.
Exception typeCondition

ArgumentException

The SqlParameter specified in the value parameter is already added to this or another SqlParameterCollection.

ArgumentNullException

The value parameter is null.

public void AddSqlParameter(SqlCommand command) 
{
    SqlParameter param = new SqlParameter(
        "@Description", SqlDbType.NVarChar, 16);
    param.Value = "Beverages";
    command.Parameters.Add(param);


Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 1.0, 1.1
Obsolete (compiler warning) in 2.0

.NET Compact Framework

Supported in: 1.0
Obsolete (compiler warning) in 2.0
Did you find this helpful?
(1500 characters remaining)

Community Additions

ADD
© 2013 Microsoft. All rights reserved.