OleDbParameterCollection 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
代表一組與 相關的 OleDbCommand 參數,以及它們對應到 DataSet欄位的映射。
public ref class OleDbParameterCollection sealed : MarshalByRefObject, System::Collections::IList, System::Data::IDataParameterCollection
public ref class OleDbParameterCollection sealed : System::Data::Common::DbParameterCollection
[System.ComponentModel.ListBindable(false)]
public sealed class OleDbParameterCollection : MarshalByRefObject, System.Collections.IList, System.Data.IDataParameterCollection
[System.ComponentModel.ListBindable(false)]
public sealed class OleDbParameterCollection : System.Data.Common.DbParameterCollection
[<System.ComponentModel.ListBindable(false)>]
type OleDbParameterCollection = class
inherit MarshalByRefObject
interface IDataParameterCollection
interface IList
interface ICollection
interface IEnumerable
[<System.ComponentModel.ListBindable(false)>]
type OleDbParameterCollection = class
inherit DbParameterCollection
Public NotInheritable Class OleDbParameterCollection
Inherits MarshalByRefObject
Implements IDataParameterCollection, IList
Public NotInheritable Class OleDbParameterCollection
Inherits DbParameterCollection
- 繼承
- 繼承
- 屬性
- 實作
範例
以下範例透過集合在 中OleDbDataAdapter建立多個 的OleDbParameterOleDbParameterCollection實例。 這些參數用於選擇資料來源中的資料並將資料置入 DataSet。 此範例假設 a DataSet 與 an OleDbDataAdapter 已透過適當的結構、指令與連線建立。
public DataSet GetDataSetFromAdapter(
DataSet dataSet, string connectionString, string queryString)
{
using (OleDbConnection connection =
new OleDbConnection(connectionString))
{
OleDbDataAdapter adapter =
new OleDbDataAdapter(queryString, connection);
// Set the parameters.
adapter.SelectCommand.Parameters.Add(
"@CategoryName", OleDbType.VarChar, 80).Value = "toasters";
adapter.SelectCommand.Parameters.Add(
"@SerialNum", OleDbType.Integer).Value = 239;
// Open the connection and fill the DataSet.
try
{
connection.Open();
adapter.Fill(dataSet);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
// The connection is automatically closed when the
// code exits the using block.
}
return dataSet;
}
Public Function GetDataSetFromAdapter( _
ByVal dataSet As DataSet, ByVal connectionString As String, _
ByVal queryString As String) As DataSet
Using connection As New OleDbConnection(connectionString)
Dim adapter As New OleDbDataAdapter(queryString, connection)
' Set the parameters.
adapter.SelectCommand.Parameters.Add( _
"@CategoryName", OleDbType.VarChar, 80).Value = "toasters"
adapter.SelectCommand.Parameters.Add( _
"@SerialNum", OleDbType.Integer).Value = 239
' Open the connection and fill the DataSet.
Try
connection.Open()
adapter.Fill(dataSet)
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
' The connection is automatically closed when the
' code exits the Using block.
End Using
Return dataSet
End Function
備註
集合中的參數數量必須等於命令文本中的參數佔位符數,否則 OLE DB 的 .NET Framework Data Provider 可能會產生錯誤。
屬性
| 名稱 | Description |
|---|---|
| Count |
回傳一個整數,包含 中 OleDbParameterCollection元素的數量。 唯讀。 |
| IsFixedSize |
會得到一個表示是否 OleDbParameterCollection 固定大小的值。 唯讀。 |
| IsReadOnly |
會得到一個值,表示 是否 OleDbParameterCollection 為唯讀。 |
| IsSynchronized |
會得到一個表示是否 OleDbParameterCollection 同步的值。 唯讀。 |
| Item[Int32] |
在指定的索引上取得或設定 。OleDbParameter |
| Item[String] |
取得或設定指定名稱的 。OleDbParameter |
| SyncRoot |
取得一個物件,可用來同步存取 OleDbParameterCollection。 唯讀。 |
方法
明確介面實作
| 名稱 | Description |
|---|---|
| IDataParameterCollection.Item[String] |
取得或設定參數於指定的索引。 (繼承來源 DbParameterCollection) |
| IList.Item[Int32] |
取得或設定位於指定索引處的專案。 (繼承來源 DbParameterCollection) |
擴充方法
| 名稱 | Description |
|---|---|
| AsParallel(IEnumerable) |
啟用查詢的平行處理。 |
| AsQueryable(IEnumerable) |
將 IEnumerable 轉換成 IQueryable。 |
| Cast<TResult>(IEnumerable) |
將 IEnumerable 的項目轉換成指定的型別。 |
| OfType<TResult>(IEnumerable) |
根據指定的型別篩選 IEnumerable 的專案。 |