OleDbParameterCollection.Add 方法

定义

重载

Add(OleDbParameter)

将指定的 OleDbParameter 添加到 OleDbParameterCollection

Add(Object)

将指定的 OleDbParameter 对象添加到 OleDbParameterCollection 中。

Add(String, OleDbType)

在给定参数名称和数据类型的情况下,将 OleDbParameter 添加到 OleDbParameterCollection 中。

Add(String, Object)
已过时.
已过时.

在给定参数名称和参数值的情况下,将 OleDbParameter 添加到 OleDbParameterCollection 中。

Add(String, OleDbType, Int32)

在给定参数名称、数据类型和列长的情况下,将 OleDbParameter 添加到 OleDbParameterCollection 中。

Add(String, OleDbType, Int32, String)

在给定参数名称、数据类型、列长和源列名称的情况下,将 OleDbParameter 添加到 OleDbParameterCollection 中。

Add(OleDbParameter)

Source:
OleDbParameterCollection.cs
Source:
OleDbParameterCollection.cs
Source:
OleDbParameterCollection.cs
Source:
OleDbParameterCollection.cs

将指定的 OleDbParameter 添加到 OleDbParameterCollection

public:
 System::Data::OleDb::OleDbParameter ^ Add(System::Data::OleDb::OleDbParameter ^ value);
public System.Data.OleDb.OleDbParameter Add (System.Data.OleDb.OleDbParameter value);
override this.Add : System.Data.OleDb.OleDbParameter -> System.Data.OleDb.OleDbParameter
member this.Add : System.Data.OleDb.OleDbParameter -> System.Data.OleDb.OleDbParameter
Public Function Add (value As OleDbParameter) As OleDbParameter

参数

value
OleDbParameter

要添加到集合中的 OleDbParameter

返回

新的 OleDbParameter 对象的索引。

例外

value 参数中指定的 OleDbParameter 已经添加到这个或其他 OleDbParameterCollection 中。

value 参数为 null。

示例

以下示例创建 并 OleDbParameterCollection 添加 OleDbParameter

public void CreateParameters()
{
    OleDbCommand command = new OleDbCommand(
        "SELECT * FROM Customers WHERE CustomerID = ?", connection);
    OleDbParameterCollection paramCollection = command.Parameters;
    OleDbParameter myParm = paramCollection.Add(
        new OleDbParameter("CustomerID", OleDbType.VarChar));
}
Public Sub CreateParameters(connection As OleDbConnection)
  Dim command As New OleDbCommand( _
    "SELECT * FROM Customers WHERE CustomerID = ?", connection)
  Dim paramCollection As OleDbParameterCollection = command.Parameters
  Dim myParm As OleDbParameter = paramCollection.Add( _
    New OleDbParameter("CustomerID", OleDbType.VarChar))
End Sub

另请参阅

适用于

Add(Object)

Source:
OleDbParameterCollectionHelper.cs
Source:
OleDbParameterCollectionHelper.cs
Source:
OleDbParameterCollectionHelper.cs
Source:
OleDbParameterCollectionHelper.cs

将指定的 OleDbParameter 对象添加到 OleDbParameterCollection 中。

public:
 override int Add(System::Object ^ value);
public:
 virtual int Add(System::Object ^ value);
public override int Add (object value);
public int Add (object value);
override this.Add : obj -> int
abstract member Add : obj -> int
override this.Add : obj -> int
Public Overrides Function Add (value As Object) As Integer
Public Function Add (value As Object) As Integer

参数

value
Object

一个 Object

返回

集合中新的 OleDbParameter 对象的索引。

实现

另请参阅

适用于

Add(String, OleDbType)

Source:
OleDbParameterCollection.cs
Source:
OleDbParameterCollection.cs
Source:
OleDbParameterCollection.cs
Source:
OleDbParameterCollection.cs

在给定参数名称和数据类型的情况下,将 OleDbParameter 添加到 OleDbParameterCollection 中。

public:
 System::Data::OleDb::OleDbParameter ^ Add(System::String ^ parameterName, System::Data::OleDb::OleDbType oleDbType);
public System.Data.OleDb.OleDbParameter Add (string? parameterName, System.Data.OleDb.OleDbType oleDbType);
public System.Data.OleDb.OleDbParameter Add (string parameterName, System.Data.OleDb.OleDbType oleDbType);
override this.Add : string * System.Data.OleDb.OleDbType -> System.Data.OleDb.OleDbParameter
member this.Add : string * System.Data.OleDb.OleDbType -> System.Data.OleDb.OleDbParameter
Public Function Add (parameterName As String, oleDbType As OleDbType) As OleDbParameter

参数

parameterName
String

参数的名称。

oleDbType
OleDbType

OleDbType 值之一。

返回

新的 OleDbParameter 对象的索引。

示例

以下示例创建 并 OleDbParameterCollection 添加 OleDbParameter

public void CreateParameters()
{
    OleDbCommand command = new OleDbCommand(
        "SELECT * FROM Customers WHERE CustomerID = ?", connection);
    OleDbParameterCollection paramCollection = command.Parameters;
    OleDbParameter myParm = paramCollection.Add(
        "CustomerID", OleDbType.VarChar);
}
Public Sub CreateParameters(connection As OleDbConnection)
  Dim command As New OleDbCommand( _
    "SELECT * FROM Customers WHERE CustomerID = ?", connection)
  Dim paramCollection As OleDbParameterCollection = command.Parameters
  Dim myParm As OleDbParameter = paramCollection.Add( _
    "CustomerID", OleDbType.VarChar)
End Sub

另请参阅

适用于

Add(String, Object)

Source:
OleDbParameterCollection.cs
Source:
OleDbParameterCollection.cs
Source:
OleDbParameterCollection.cs
Source:
OleDbParameterCollection.cs

注意

Add(String parameterName, Object value) has been deprecated. Use AddWithValue(String parameterName, Object value) instead.

注意

Add(String parameterName, Object value) has been deprecated. Use AddWithValue(String parameterName, Object value). http://go.microsoft.com/fwlink/?linkid=14202

在给定参数名称和参数值的情况下,将 OleDbParameter 添加到 OleDbParameterCollection 中。

public:
 System::Data::OleDb::OleDbParameter ^ Add(System::String ^ parameterName, System::Object ^ value);
[System.Obsolete("Add(String parameterName, Object value) has been deprecated. Use AddWithValue(String parameterName, Object value) instead.")]
public System.Data.OleDb.OleDbParameter Add (string? parameterName, object? value);
public System.Data.OleDb.OleDbParameter Add (string parameterName, object value);
[System.Obsolete("Add(String parameterName, Object value) has been deprecated.  Use AddWithValue(String parameterName, Object value).  http://go.microsoft.com/fwlink/?linkid=14202", false)]
public System.Data.OleDb.OleDbParameter Add (string parameterName, object value);
[<System.Obsolete("Add(String parameterName, Object value) has been deprecated. Use AddWithValue(String parameterName, Object value) instead.")>]
override this.Add : string * obj -> System.Data.OleDb.OleDbParameter
member this.Add : string * obj -> System.Data.OleDb.OleDbParameter
[<System.Obsolete("Add(String parameterName, Object value) has been deprecated.  Use AddWithValue(String parameterName, Object value).  http://go.microsoft.com/fwlink/?linkid=14202", false)>]
override this.Add : string * obj -> System.Data.OleDb.OleDbParameter
Public Function Add (parameterName As String, value As Object) As OleDbParameter

参数

parameterName
String

参数的名称。

value
Object

要添加到集合中的 OleDbParameterValue

返回

新的 OleDbParameter 对象的索引。

属性

例外

value 参数不是一个 OleDbParameter

注解

使用此方法重 Add 载指定整数参数值时,请谨慎。 由于此重载采用 value 类型的 Object,因此必须在值为零时将 Object 值转换为类型,如以下 C# 示例所示。

parameters.Add("@pname", Convert.ToInt32(0));  

如果不执行此转换,编译器将假定你正在尝试调用 Add 重载。

另请参阅

适用于

Add(String, OleDbType, Int32)

Source:
OleDbParameterCollection.cs
Source:
OleDbParameterCollection.cs
Source:
OleDbParameterCollection.cs
Source:
OleDbParameterCollection.cs

在给定参数名称、数据类型和列长的情况下,将 OleDbParameter 添加到 OleDbParameterCollection 中。

public:
 System::Data::OleDb::OleDbParameter ^ Add(System::String ^ parameterName, System::Data::OleDb::OleDbType oleDbType, int size);
public System.Data.OleDb.OleDbParameter Add (string? parameterName, System.Data.OleDb.OleDbType oleDbType, int size);
public System.Data.OleDb.OleDbParameter Add (string parameterName, System.Data.OleDb.OleDbType oleDbType, int size);
override this.Add : string * System.Data.OleDb.OleDbType * int -> System.Data.OleDb.OleDbParameter
member this.Add : string * System.Data.OleDb.OleDbType * int -> System.Data.OleDb.OleDbParameter
Public Function Add (parameterName As String, oleDbType As OleDbType, size As Integer) As OleDbParameter

参数

parameterName
String

参数的名称。

oleDbType
OleDbType

OleDbType 值之一。

size
Int32

列的长度。

返回

新的 OleDbParameter 对象的索引。

示例

以下示例创建 一个 OleDbParameterCollection,将 实例 OleDbParameter 添加到 集合,并返回对新 OleDbParameter的引用。

public void CreateParameters(OleDbConnection connection)
{
    OleDbCommand command = new OleDbCommand(
        "SELECT * FROM Customers WHERE CustomerID = ?", connection);
    OleDbParameterCollection paramCollection = command.Parameters;
    OleDbParameter parameter = paramCollection.Add(
        "CustomerID", OleDbType.VarChar, 5);
}
Public Sub CreateParameters(connection As OleDbConnection)
  Dim command As New OleDbCommand( _
    "SELECT * FROM Customers WHERE CustomerID = ?", connection)
  Dim paramCollection As OleDbParameterCollection = command.Parameters
  Dim parameter As OleDbParameter = paramCollection.Add( _
    "CustomerID", OleDbType.VarChar, 5)
End Sub

另请参阅

适用于

Add(String, OleDbType, Int32, String)

Source:
OleDbParameterCollection.cs
Source:
OleDbParameterCollection.cs
Source:
OleDbParameterCollection.cs
Source:
OleDbParameterCollection.cs

在给定参数名称、数据类型、列长和源列名称的情况下,将 OleDbParameter 添加到 OleDbParameterCollection 中。

public:
 System::Data::OleDb::OleDbParameter ^ Add(System::String ^ parameterName, System::Data::OleDb::OleDbType oleDbType, int size, System::String ^ sourceColumn);
public System.Data.OleDb.OleDbParameter Add (string? parameterName, System.Data.OleDb.OleDbType oleDbType, int size, string? sourceColumn);
public System.Data.OleDb.OleDbParameter Add (string parameterName, System.Data.OleDb.OleDbType oleDbType, int size, string sourceColumn);
override this.Add : string * System.Data.OleDb.OleDbType * int * string -> System.Data.OleDb.OleDbParameter
member this.Add : string * System.Data.OleDb.OleDbType * int * string -> System.Data.OleDb.OleDbParameter
Public Function Add (parameterName As String, oleDbType As OleDbType, size As Integer, sourceColumn As String) As OleDbParameter

参数

parameterName
String

参数的名称。

oleDbType
OleDbType

OleDbType 值之一。

size
Int32

列的长度。

sourceColumn
String

源列的名称。

返回

新的 OleDbParameter 对象的索引。

示例

以下示例创建 一个 OleDbParameterCollection,将 实例 OleDbParameter 添加到 集合,并返回对新 OleDbParameter的引用。

public void CreateParameters(OleDbConnection connection)
{
    OleDbCommand command = new OleDbCommand(
        "SELECT * FROM Customers WHERE CustomerID = ?", connection);
    OleDbParameterCollection paramCollection = command.Parameters;
    OleDbParameter parameter = paramCollection.Add(
        "CustomerID", OleDbType.VarChar, 5, "CustomerID");
}
Public Sub CreateParameters(connection As OleDbConnection)
  Dim command As New OleDbCommand( _
    "SELECT * FROM Customers WHERE CustomerID = ?", connection)
  Dim paramCollection As OleDbParameterCollection = command.Parameters
  Dim parameter As OleDbParameter = paramCollection.Add( _
    "CustomerID", OleDbType.VarChar, 5, "CustomerID")
End Sub

另请参阅

适用于