OleDbParameter 類別

定義

表示 OleDbCommand 的參數,並選擇性地表示其對於 DataSet 資料行的對應。Represents a parameter to an OleDbCommand and optionally its mapping to a DataSet column. 此類別無法獲得繼承。This class cannot be inherited.

public ref class OleDbParameter sealed : System::Data::Common::DbParameter, ICloneable
public ref class OleDbParameter sealed : MarshalByRefObject, ICloneable, System::Data::IDbDataParameter
[System.ComponentModel.TypeConverter(typeof(System.Data.OleDb.OleDbParameter/OleDbParameterConverter))]
public sealed class OleDbParameter : System.Data.Common.DbParameter, ICloneable
[System.ComponentModel.TypeConverter(typeof(System.Data.OleDb.OleDbParameterConverter))]
public sealed class OleDbParameter : MarshalByRefObject, ICloneable, System.Data.IDbDataParameter
[<System.ComponentModel.TypeConverter(typeof(System.Data.OleDb.OleDbParameter/OleDbParameterConverter))>]
type OleDbParameter = class
    inherit DbParameter
    interface IDataParameter
    interface IDbDataParameter
    interface ICloneable
[<System.ComponentModel.TypeConverter(typeof(System.Data.OleDb.OleDbParameterConverter))>]
type OleDbParameter = class
    inherit MarshalByRefObject
    interface IDbDataParameter
    interface IDataParameter
    interface ICloneable
[<System.ComponentModel.TypeConverter(typeof(System.Data.OleDb.OleDbParameter/OleDbParameterConverter))>]
type OleDbParameter = class
    inherit DbParameter
    interface ICloneable
    interface IDbDataParameter
    interface IDataParameter
Public NotInheritable Class OleDbParameter
Inherits DbParameter
Implements ICloneable
Public NotInheritable Class OleDbParameter
Inherits MarshalByRefObject
Implements ICloneable, IDbDataParameter
繼承
OleDbParameter
繼承
繼承
OleDbParameter
屬性
實作

範例

下列範例會 OleDbParameter 透過中的集合建立多個實例 OleDbParameterCollection OleDbDataAdapterThe following example creates multiple instances of OleDbParameter through the OleDbParameterCollection collection within the OleDbDataAdapter. 這些參數可用來從資料來源選取資料,並將資料放在中 DataSetThese parameters are used to select data from the data source and place the data in the DataSet. 這個範例假設 DataSet OleDbDataAdapter 已經使用適當的架構、命令和連接來建立和。This example assumes that a DataSet and an OleDbDataAdapter have already been created by using the appropriate schema, commands, and connection.

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 使用以問號 (? ) 而非具名引數來標記的位置參數。The OLE DB.NET Framework Data Provider uses positional parameters that are marked with a question mark (?) instead of named parameters.

使用 Microsoft OLE DB Provider for Oracle (MSDAORA) 和 OLE DB.NET Framework Data Provider 來查詢 Oracle 資料庫時,使用 LIKE 子句來查詢固定長度欄位中的值,可能不會傳回所有預期的相符專案。When querying an Oracle database using the Microsoft OLE DB Provider for Oracle (MSDAORA) and the OLE DB.NET Framework Data Provider, using the LIKE clause to query values in fixed-length fields may not return all expected matches. 原因是當 Oracle 符合子句中固定長度欄位的值時 LIKE ,它會比對字串的整個長度,包括填補尾端空白。The reason is that when Oracle matches values for fixed-length fields in a LIKE clause, it matches the entire length of the string, including any padding trailing spaces. 例如,如果 Oracle 資料庫中的資料表包含名為 "Field1" 且定義為的欄位, char(3) 而且您在該資料表的資料列中輸入 "a" 值,則下列程式碼不會傳回資料列。For example, if a table in an Oracle database contains a field named "Field1" that is defined as char(3), and you enter the value "a" into a row of that table, the following code does not return the row.

Dim queryString As String = "SELECT * FROM Table1 WHERE Field1 LIKE ?"  
Dim command As OleDbCommand = New OleDbCommand(queryString, connection)  
command.Parameters.Add("@p1", OleDbType.Char, 3).Value = "a"  
Dim reader As OleDbDataReader = command.ExecuteReader()  
string queryString = "SELECT * FROM Table1 WHERE Field1 LIKE ?";  
OleDbCommand command = new OleDbCommand(queryString, connection);  
command.Parameters.Add("@p1", OleDbType.Char, 3).Value = "a";  
OleDbDataReader reader = command.ExecuteReader();  

這是因為 Oracle 會將資料行值儲存為 "a" (填補 "a" (尾端空白)至固定欄位長度 3) ,而 Oracle 在比較固定長度的欄位時,不會將其視為參數值 "a" 的相符項 LIKEThis is because Oracle stores the column value as "a " (padding "a", with trailing spaces, to the fixed field length of 3), which Oracle does not treat as a match for the parameter value of "a" in the case of a LIKE comparison of fixed-length fields.

若要解決這個問題,請將百分比 ( "%" ) 萬用字元附加到參數值 ("a%") ,或改用 SQL = 比較。To resolve this problem, append a percentage ("%") wildcard character to the parameter value ("a%"), or use an SQL = comparison instead.

建構函式

OleDbParameter()

初始化 OleDbParameter 類別的新執行個體。Initializes a new instance of the OleDbParameter class.

OleDbParameter(String, Object)

初始化 OleDbParameter 類別的新執行個體,該類別使用參數名稱和新 OleDbParameter 的值。Initializes a new instance of the OleDbParameter class that uses the parameter name and the value of the new OleDbParameter.

OleDbParameter(String, OleDbType)

初始化 OleDbParameter 類別的新執行個體,該類別使用參數名稱和資料型別。Initializes a new instance of the OleDbParameter class that uses the parameter name and data type.

OleDbParameter(String, OleDbType, Int32)

初始化 OleDbParameter 類別的新執行個體,該類別使用參數名稱、資料型別和長度。Initializes a new instance of the OleDbParameter class that uses the parameter name, data type, and length.

OleDbParameter(String, OleDbType, Int32, ParameterDirection, Boolean, Byte, Byte, String, DataRowVersion, Object)

初始化 OleDbParameter類別的新執行個體,它使用參數名稱、資料類型、長度、來源資料行名稱、參數方向、數值有效位數,以及其他屬性。Initializes a new instance of the OleDbParameter class that uses the parameter name, data type, length, source column name, parameter direction, numeric precision, and other properties.

OleDbParameter(String, OleDbType, Int32, ParameterDirection, Byte, Byte, String, DataRowVersion, Boolean, Object)

初始化 OleDbParameter類別的新執行個體,它使用參數名稱、資料類型、長度、來源資料行名稱、參數方向、數值有效位數,以及其他屬性。Initializes a new instance of the OleDbParameter class that uses the parameter name, data type, length, source column name, parameter direction, numeric precision, and other properties.

OleDbParameter(String, OleDbType, Int32, String)

初始化 OleDbParameter 類別的新執行個體,該類別使用參數名稱、資料型別、長度和來源資料行名稱。Initializes a new instance of the OleDbParameter class that uses the parameter name, data type, length, and source column name.

屬性

DbType

取得或設定參數的 DbTypeGets or sets the DbType of the parameter.

Direction

取得或設定值,指出參數是否為只能輸入、只能輸出、雙向或預存程序傳回值參數。Gets or sets a value that indicates whether the parameter is input-only, output-only, bidirectional, or a stored procedure return-value parameter.

IsNullable

取得或設定值,這個值指出該參數是否接受 null 值。Gets or sets a value that indicates whether the parameter accepts null values.

Offset
OleDbType

取得或設定參數的 OleDbTypeGets or sets the OleDbType of the parameter.

ParameterName

取得或設定 OleDbParameter 的名稱。Gets or sets the name of the OleDbParameter.

Precision

取得或設定用來表示 Value 屬性的最大位數。Gets or sets the maximum number of digits used to represent the Value property.

Scale

取得或設定 Value 所解析的小數點位數。Gets or sets the number of decimal places to which Value is resolved.

Size

取得或設定資料行中資料的最大大小 (以位元組為單位)。Gets or sets the maximum size, in bytes, of the data within the column.

SourceColumn

取得或設定來源資料行的名稱,這個資料行對應至 DataSet,並用來載入或傳回 ValueGets or sets the name of the source column mapped to the DataSet and used for loading or returning the Value.

SourceColumnNullMapping

取得或設定值,這個值表示來源資料行是否可為 Null。Gets or sets a value which indicates whether the source column is nullable. 這可讓 DbCommandBuilder 正確產生可為 Null 的資料行的 Update 陳述式。This allows DbCommandBuilder to correctly generate Update statements for nullable columns.

SourceVersion

取得或設定載入 DataRowVersion 時要使用的 ValueGets or sets the DataRowVersion to use when you load Value.

Value

取得或設定參數的值。Gets or sets the value of the parameter.

方法

CreateObjRef(Type)

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

(繼承來源 MarshalByRefObject)
Equals(Object)

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

(繼承來源 Object)
GetHashCode()

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

(繼承來源 Object)
GetLifetimeService()
已過時。

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

(繼承來源 MarshalByRefObject)
GetType()

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

(繼承來源 Object)
InitializeLifetimeService()
已過時。

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

(繼承來源 MarshalByRefObject)
MemberwiseClone()

建立目前 Object 的淺層複製。Creates a shallow copy of the current Object.

(繼承來源 Object)
MemberwiseClone(Boolean)

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

(繼承來源 MarshalByRefObject)
ResetDbType()

重設與此 OleDbParameter 相關聯的類型。Resets the type associated with this OleDbParameter.

ResetOleDbType()

重設與此 OleDbParameter 相關聯的類型。Resets the type associated with this OleDbParameter.

ToString()

取得包含 ParameterName 的字串。Gets a string that contains the ParameterName.

明確介面實作

ICloneable.Clone()

如需這個成員的說明,請參閱 Clone()For a description of this member, see Clone().

IDataParameter.SourceVersion

取得或設定 DataRowVersion,以在載入 Value 時使用。Gets or sets the DataRowVersion to use when loading Value.

(繼承來源 DbParameter)
IDbDataParameter.Precision

表示數值參數的整數位數。Indicates the precision of numeric parameters.

(繼承來源 DbParameter)
IDbDataParameter.Scale

如需這個成員的說明,請參閱 ScaleFor a description of this member, see Scale.

(繼承來源 DbParameter)

適用於

另請參閱