共用方式為


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)

來源:
OleDbParameterCollection.cs
來源:
OleDbParameterCollection.cs
來源:
OleDbParameterCollection.cs
來源:
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)

來源:
OleDbParameterCollectionHelper.cs
來源:
OleDbParameterCollectionHelper.cs
來源:
OleDbParameterCollectionHelper.cs
來源:
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)

來源:
OleDbParameterCollection.cs
來源:
OleDbParameterCollection.cs
來源:
OleDbParameterCollection.cs
來源:
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)

來源:
OleDbParameterCollection.cs
來源:
OleDbParameterCollection.cs
來源:
OleDbParameterCollection.cs
來源:
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)

來源:
OleDbParameterCollection.cs
來源:
OleDbParameterCollection.cs
來源:
OleDbParameterCollection.cs
來源:
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)

來源:
OleDbParameterCollection.cs
來源:
OleDbParameterCollection.cs
來源:
OleDbParameterCollection.cs
來源:
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

另請參閱

適用於