SqlParameterCollection 類別
本文內容
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
表示與 SqlCommand 相關聯的參數集合,以及它們與 DataSet中的數據行對應。 無法繼承這個類別。
public ref class SqlParameterCollection sealed : System::Data::Common::DbParameterCollection
public ref class SqlParameterCollection sealed : MarshalByRefObject, System::Collections::IList, System::Data::IDataParameterCollection
public sealed class SqlParameterCollection : System.Data.Common.DbParameterCollection
[System.ComponentModel.ListBindable(false)]
public sealed class SqlParameterCollection : MarshalByRefObject, System.Collections.IList, System.Data.IDataParameterCollection
[System.ComponentModel.ListBindable(false)]
public sealed class SqlParameterCollection : System.Data.Common.DbParameterCollection
type SqlParameterCollection = class
inherit DbParameterCollection
[<System.ComponentModel.ListBindable(false)>]
type SqlParameterCollection = class
inherit MarshalByRefObject
interface IDataParameterCollection
interface IList
interface ICollection
interface IEnumerable
[<System.ComponentModel.ListBindable(false)>]
type SqlParameterCollection = class
inherit DbParameterCollection
Public NotInheritable Class SqlParameterCollection
Inherits DbParameterCollection
Public NotInheritable Class SqlParameterCollection
Inherits MarshalByRefObject
Implements IDataParameterCollection, IList
- 繼承
- 繼承
- 繼承
- 屬性
- 實作
下列範例會透過 SqlParameterCollection 集合建立多個 SqlParameter 實例。 參數可用來選取數據源中的數據,並填入 DataSet。 此程式代碼假設已使用適當的架構、命令和連線來建立 DataSet 和 SqlDataAdapter。
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 引發錯誤。 使用預存程式時,必須提供預存程式中宣告且不含預設值的所有參數。 使用預設值宣告的參數是選擇性的。 這可讓您指定預設值以外的值。
如需示範如何使用參數的其他範例程式代碼的詳細資訊,請參閱 命令和參數。
Count |
傳回 Integer,其中包含 SqlParameterCollection中的項目數。 唯讀的。 |
Is |
取得值,這個值表示 SqlParameterCollection 是否有固定大小。 |
Is |
指定集合是否為固定大小。 (繼承來源 DbParameterCollection) |
Is |
取得值,這個值表示 SqlParameterCollection 是否為唯讀。 |
Is |
指定集合是否為唯讀。 (繼承來源 DbParameterCollection) |
Is |
取得值,這個值表示是否同步處理 SqlParameterCollection。 |
Is |
指定集合是否同步處理。 (繼承來源 DbParameterCollection) |
Item[Int32] |
取得指定索引處的 SqlParameter。 |
Item[String] |
取得具有指定名稱的 SqlParameter。 |
Sync |
取得對象,這個物件可用來同步存取 SqlParameterCollection。 |
ICollection. |
取得值,指出是否同步存取 ICollection (線程安全)。 (繼承來源 DbParameterCollection) |
IData |
取得或設定位於指定索引處的參數。 (繼承來源 DbParameterCollection) |
IList. |
取得值,指出 IList 是否有固定大小。 (繼承來源 DbParameterCollection) |
IList. |
取得值,指出 IList 是否為唯讀。 (繼承來源 DbParameterCollection) |
IList. |
取得或設定位於指定索引處的專案。 (繼承來源 DbParameterCollection) |
Cast<TResult>(IEnumerable) |
將 IEnumerable 的項目轉換成指定的型別。 |
Of |
根據指定的型別篩選 IEnumerable 的專案。 |
As |
啟用查詢的平行處理。 |
As |
將 IEnumerable 轉換成 IQueryable。 |
產品 | 版本 |
---|---|
.NET | Core 1.0, Core 1.1 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 2.0 |