SqlParameterCollection SqlParameterCollection SqlParameterCollection SqlParameterCollection Class

定義

代表與 SqlCommand 相關聯的參數以及其與 DataSet 中資料行之個別對應的集合。Represents a collection of parameters associated with a SqlCommand and their respective mappings to columns in a DataSet. 這個類別無法被繼承。This class cannot be inherited.

public ref class SqlParameterCollection sealed : System::Data::Common::DbParameterCollection, System::Collections::IList
[System.ComponentModel.ListBindable(false)]
public sealed class SqlParameterCollection : System.Data.Common.DbParameterCollection, System.Collections.IList
type SqlParameterCollection = class
    inherit DbParameterCollection
    interface IDataParameterCollection
    interface IList
    interface ICollection
    interface IEnumerable
Public NotInheritable Class SqlParameterCollection
Inherits DbParameterCollection
Implements IList
繼承
SqlParameterCollectionSqlParameterCollectionSqlParameterCollectionSqlParameterCollection
屬性
實作

範例

下列範例會SqlParameterCollection透過集合建立的SqlParameter多個實例。The following example creates multiple instances of SqlParameter through the SqlParameterCollection collection. 參數是用來選取資料來源內的資料, 並填入DataSetThe parameters are used to select data within the data source and populate the DataSet. 此程式DataSet代碼假設已經使用適當SqlDataAdapter的架構、命令和連接建立和。This code assumes that a DataSet and a SqlDataAdapter have already been created with the appropriate schema, commands, and connection.

public void AddSqlParameters() 
{
// ...
// create categoriesDataSet and categoriesAdapter
// ...

  categoriesAdapter.SelectCommand.Parameters.Add(
    "@CategoryName", SqlDbType.VarChar, 80).Value = "toasters";
  categoriesAdapter.SelectCommand.Parameters.Add(
    "@SerialNum", SqlDbType.Int).Value = 239;
  categoriesAdapter.Fill(categoriesDataSet);

}
Public Sub AddSqlParameters()
    ' ...
    ' create categoriesDataSet and categoriesAdapter
    ' ...
    categoriesAdapter.SelectCommand.Parameters.Add( _
        "@CategoryName", SqlDbType.VarChar, 80).Value = "toasters"
    categoriesAdapter.SelectCommand.Parameters.Add( _
        "@SerialNum", SqlDbType.Int).Value = 239
    
    categoriesAdapter.Fill(categoriesDataSet)
End Sub  

備註

如果命令包含臨機操作 SQL 語句, 而不是預存程式名稱, 則集合中的參數數目必須等於命令文字內的參數預留位置數目, 否則 SQL Server 會引發錯誤。If the command contains an ad hoc SQL statement, as opposed to a stored-procedure name, the number of the parameters in the collection must be equal to the number of parameter placeholders within the command text, or SQL Server raises an error. 使用預存程式時, 必須提供預存程式中所有不含預設值的參數。With a stored procedure, all the parameters declared in the stored procedure without a default value must be provided. 使用預設值宣告的參數是選擇性的。Parameters declared with a default value are optional. 這可讓您指定預設以外的值。This lets you specify a value other than the default.

如需示範如何使用參數之其他範例程式碼的詳細資訊, 請參閱命令和參數For more information with additional sample code demonstrating how to use parameters, see Commands and Parameters.

屬性

Count Count Count Count

傳回包含 SqlParameterCollection 中之項目數目的整數。Returns an Integer that contains the number of elements in the SqlParameterCollection. 唯讀。Read-only.

IsFixedSize IsFixedSize IsFixedSize IsFixedSize

取得值,指出 SqlParameterCollection 是否有固定的大小。Gets a value that indicates whether the SqlParameterCollection has a fixed size.

IsReadOnly IsReadOnly IsReadOnly IsReadOnly

取得值,這個值表示 SqlParameterCollection 是否為唯讀。Gets a value that indicates whether the SqlParameterCollection is read-only.

IsSynchronized IsSynchronized IsSynchronized IsSynchronized

取得值,表示 SqlParameterCollection 是否同步處理。Gets a value that indicates whether the SqlParameterCollection is synchronized.

Item[Int32] Item[Int32] Item[Int32] Item[Int32]

取得指定索引處的 SqlParameterGets the SqlParameter at the specified index.

Item[String] Item[String] Item[String] Item[String]

取得具有指定名稱的 SqlParameterGets the SqlParameter with the specified name.

SyncRoot SyncRoot SyncRoot SyncRoot

取得可用以同步存取 SqlParameterCollection 的物件。Gets an object that can be used to synchronize access to the SqlParameterCollection.

方法

Add(Object) Add(Object) Add(Object) Add(Object)

將指定的 SqlParameter 物件加入至 SqlParameterCollectionAdds the specified SqlParameter object to the SqlParameterCollection.

Add(SqlParameter) Add(SqlParameter) Add(SqlParameter) Add(SqlParameter)

將指定的 SqlParameter 物件加入至 SqlParameterCollectionAdds the specified SqlParameter object to the SqlParameterCollection.

Add(String, Object) Add(String, Object) Add(String, Object) Add(String, Object)

將指定的 SqlParameter 物件加入至 SqlParameterCollectionAdds the specified SqlParameter object to the SqlParameterCollection.

Add(String, SqlDbType) Add(String, SqlDbType) Add(String, SqlDbType) Add(String, SqlDbType)

SqlParameter 加入至 SqlParameterCollection (已知參數名稱和資料類型)。Adds a SqlParameter to the SqlParameterCollection given the parameter name and the data type.

Add(String, SqlDbType, Int32) Add(String, SqlDbType, Int32) Add(String, SqlDbType, Int32) Add(String, SqlDbType, Int32)

SqlParameter 加入至具有指定參數名稱、SqlParameterCollection 和大小的 SqlDbTypeAdds a SqlParameter to the SqlParameterCollection, given the specified parameter name, SqlDbType and size.

Add(String, SqlDbType, Int32, String) Add(String, SqlDbType, Int32, String) Add(String, SqlDbType, Int32, String) Add(String, SqlDbType, Int32, String)

SqlParameter 加入至 SqlParameterCollection (已知參數名稱、資料類型和資料行長度)。Adds a SqlParameter to the SqlParameterCollection with the parameter name, the data type, and the column length.

AddRange(Array) AddRange(Array) AddRange(Array) AddRange(Array)

將值陣列加入至 SqlParameterCollection 結尾。Adds an array of values to the end of the SqlParameterCollection.

AddRange(SqlParameter[]) AddRange(SqlParameter[]) AddRange(SqlParameter[]) AddRange(SqlParameter[])

SqlParameter 值陣列加入至 SqlParameterCollection 結尾。Adds an array of SqlParameter values to the end of the SqlParameterCollection.

AddWithValue(String, Object) AddWithValue(String, Object) AddWithValue(String, Object) AddWithValue(String, Object)

將值加入至 SqlParameterCollection 結尾。Adds a value to the end of the SqlParameterCollection.

Clear() Clear() Clear() Clear()

SqlParameter 移除所有的 SqlParameterCollection 物件。Removes all the SqlParameter objects from the SqlParameterCollection.

Contains(Object) Contains(Object) Contains(Object) Contains(Object)

判斷指定的 Object 是否在這個 SqlParameterCollection 中。Determines whether the specified Object is in this SqlParameterCollection.

Contains(SqlParameter) Contains(SqlParameter) Contains(SqlParameter) Contains(SqlParameter)

判斷指定的 SqlParameter 是否在這個 SqlParameterCollection 中。Determines whether the specified SqlParameter is in this SqlParameterCollection.

Contains(String) Contains(String) Contains(String) Contains(String)

判斷指定的參數名稱是否在 SqlParameterCollection 中。Determines whether the specified parameter name is in this SqlParameterCollection.

CopyTo(Array, Int32) CopyTo(Array, Int32) CopyTo(Array, Int32) CopyTo(Array, Int32)

將目前 SqlParameterCollection 的所有項目複製到指定的一維 Array,從指定的目的 Array 索引開始。Copies all the elements of the current SqlParameterCollection to the specified one-dimensional Array starting at the specified destination Array index.

CopyTo(SqlParameter[], Int32) CopyTo(SqlParameter[], Int32) CopyTo(SqlParameter[], Int32) CopyTo(SqlParameter[], Int32)

將目前 SqlParameterCollection 的所有項目複製到指定的 SqlParameterCollection,從指定的目的索引開始。Copies all the elements of the current SqlParameterCollection to the specified SqlParameterCollection starting at the specified destination index.

CreateObjRef(Type) CreateObjRef(Type) CreateObjRef(Type) CreateObjRef(Type)

建立包含所有相關資訊的物件,這些資訊是產生用來與遠端物件通訊的所需 Proxy。Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(Inherited from MarshalByRefObject)
Equals(Object) Equals(Object) Equals(Object) Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetEnumerator() GetEnumerator() GetEnumerator() GetEnumerator()

傳回在 SqlParameterCollection 中逐一查看的列舉值。Returns an enumerator that iterates through the SqlParameterCollection.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(Inherited from Object)
GetLifetimeService() GetLifetimeService() GetLifetimeService() GetLifetimeService()

擷取控制這個執行個體存留期 (Lifetime) 原則的目前存留期服務物件。Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
GetType() GetType() GetType() GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(Inherited from Object)
IndexOf(Object) IndexOf(Object) IndexOf(Object) IndexOf(Object)

取得集合中指定的 Object 位置。Gets the location of the specified Object within the collection.

IndexOf(SqlParameter) IndexOf(SqlParameter) IndexOf(SqlParameter) IndexOf(SqlParameter)

取得集合中指定的 SqlParameter 位置。Gets the location of the specified SqlParameter within the collection.

IndexOf(String) IndexOf(String) IndexOf(String) IndexOf(String)

取得集合中具有指定名稱之指定 SqlParameter 的位置。Gets the location of the specified SqlParameter with the specified name.

InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService()

取得存留期服務物件,以控制這個執行個體的存留期原則。Obtains a lifetime service object to control the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
Insert(Int32, Object) Insert(Int32, Object) Insert(Int32, Object) Insert(Int32, Object)

Object 插入至 SqlParameterCollection 的指定索引處。Inserts an Object into the SqlParameterCollection at the specified index.

Insert(Int32, SqlParameter) Insert(Int32, SqlParameter) Insert(Int32, SqlParameter) Insert(Int32, SqlParameter)

SqlParameter 物件插入 SqlParameterCollection 的指定索引處。Inserts a SqlParameter object into the SqlParameterCollection at the specified index.

MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(Inherited from Object)
MemberwiseClone(Boolean) MemberwiseClone(Boolean) MemberwiseClone(Boolean) MemberwiseClone(Boolean)

建立目前 MarshalByRefObject 物件的淺層複本。Creates a shallow copy of the current MarshalByRefObject object.

(Inherited from MarshalByRefObject)
Remove(Object) Remove(Object) Remove(Object) Remove(Object)

從集合移除指定的 SqlParameterRemoves the specified SqlParameter from the collection.

Remove(SqlParameter) Remove(SqlParameter) Remove(SqlParameter) Remove(SqlParameter)

從集合移除指定的 SqlParameterRemoves the specified SqlParameter from the collection.

RemoveAt(Int32) RemoveAt(Int32) RemoveAt(Int32) RemoveAt(Int32)

SqlParameter 的指定索引處移除 SqlParameterCollectionRemoves the SqlParameter from the SqlParameterCollection at the specified index.

RemoveAt(String) RemoveAt(String) RemoveAt(String) RemoveAt(String)

SqlParameter 的指定參數名稱處移除 SqlParameterCollectionRemoves the SqlParameter from the SqlParameterCollection at the specified parameter name.

ToString() ToString() ToString() ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(Inherited from Object)

擴充方法

Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable)

IEnumerable 的項目轉換成指定的型別。Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable)

根據指定的型別來篩選 IEnumerable 的項目。Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable) AsParallel(IEnumerable) AsParallel(IEnumerable) AsParallel(IEnumerable)

啟用查詢的平行化作業。Enables parallelization of a query.

AsQueryable(IEnumerable) AsQueryable(IEnumerable) AsQueryable(IEnumerable) AsQueryable(IEnumerable)

IEnumerable 轉換成 IQueryableConverts an IEnumerable to an IQueryable.

適用於

另請參閱