OdbcParameter 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
代表一個參數到 , OdbcCommand 且可選擇性地將其映射到 DataColumn。 此類別無法獲得繼承。
public ref class OdbcParameter sealed : MarshalByRefObject, ICloneable, System::Data::IDbDataParameter
public ref class OdbcParameter sealed : System::Data::Common::DbParameter, ICloneable
[System.ComponentModel.TypeConverter(typeof(System.Data.Odbc.OdbcParameterConverter))]
public sealed class OdbcParameter : MarshalByRefObject, ICloneable, System.Data.IDbDataParameter
[System.ComponentModel.TypeConverter(typeof(System.Data.Odbc.OdbcParameter+OdbcParameterConverter))]
public sealed class OdbcParameter : System.Data.Common.DbParameter, ICloneable
[<System.ComponentModel.TypeConverter(typeof(System.Data.Odbc.OdbcParameterConverter))>]
type OdbcParameter = class
inherit MarshalByRefObject
interface IDbDataParameter
interface IDataParameter
interface ICloneable
[<System.ComponentModel.TypeConverter(typeof(System.Data.Odbc.OdbcParameter+OdbcParameterConverter))>]
type OdbcParameter = class
inherit DbParameter
interface ICloneable
interface IDbDataParameter
interface IDataParameter
Public NotInheritable Class OdbcParameter
Inherits MarshalByRefObject
Implements ICloneable, IDbDataParameter
Public NotInheritable Class OdbcParameter
Inherits DbParameter
Implements ICloneable
- 繼承
- 繼承
- 屬性
- 實作
範例
以下範例透過 在 OdbcParameterOdbcParameterCollection內建立多個 的OdbcDataAdapter實例。 這些參數用於從資料來源中選擇資料並將資料放入 DataSet。 此範例假設 a DataSet 與 an OdbcDataAdapter 已透過適當的結構、指令與連線建立。
public DataSet GetDataSetFromAdapter(
DataSet dataSet, string connectionString, string queryString)
{
using (OdbcConnection connection =
new OdbcConnection(connectionString))
{
OdbcDataAdapter adapter =
new OdbcDataAdapter(queryString, connection);
// Set the parameters.
adapter.SelectCommand.Parameters.Add(
"@CategoryName", OdbcType.VarChar, 80).Value = "toasters";
adapter.SelectCommand.Parameters.Add(
"@SerialNum", OdbcType.Int).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 OdbcConnection(connectionString)
Dim adapter As New OdbcDataAdapter(queryString, connection)
' Set the parameters.
adapter.SelectCommand.Parameters.Add( _
"@CategoryName", OdbcType.VarChar, 80).Value = "toasters"
adapter.SelectCommand.Parameters.Add( _
"@SerialNum", OdbcType.Int).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
備註
參數名稱不區分大小寫。
當使用 Microsoft OLE DB Provider for Oracle (MSDAORA) 和 ODBC .NET Framework Data Provider 查詢 Oracle 資料庫時,使用 LIKE 子句查詢固定長度欄位的值,可能無法回傳所有預期匹配。 原因在於當 Oracle 匹配子句中 LIKE 固定長度欄位的值時,會匹配整個字串長度,包括任何填充後方空格。 例如,若 Oracle 資料庫中的某個資料表包含一個名為「Field1」的欄位,定義為 char(3),且你在該資料表的某一列輸入值「a」,以下程式碼將不會回傳該列。
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」 LIKE 視為與參數值的匹配。
為了解決此問題,可以在參數值()"a%"後加上百分比(「%」)通配字元,或改用 SQL = 比較。
建構函式
| 名稱 | Description |
|---|---|
| OdbcParameter() |
初始化 OdbcParameter 類別的新執行個體。 |
| OdbcParameter(String, Object) |
初始化一個使用參數名稱和OdbcParameter物件的類別新實例OdbcParameter。 |
| OdbcParameter(String, OdbcType, Int32, ParameterDirection, Boolean, Byte, Byte, String, DataRowVersion, Object) |
初始化一個新的類別實例,該實例 OdbcParameter 使用參數名稱、資料型別、長度、來源欄位名稱、參數方向、數值精度及其他屬性。 |
| OdbcParameter(String, OdbcType, Int32, ParameterDirection, Byte, Byte, String, DataRowVersion, Boolean, Object) |
初始化一個新的類別實例,該實例 OdbcParameter 使用參數名稱、資料型別、長度、來源欄位名稱、參數方向、數值精度及其他屬性。 |
| OdbcParameter(String, OdbcType, Int32, String) |
初始化一個使用參數名稱、資料型態、長度及來源欄位名稱的類別新實例 OdbcParameter 。 |
| OdbcParameter(String, OdbcType, Int32) |
初始化一個使用參數名稱、資料型態及長度的新類別實例 OdbcParameter 。 |
| OdbcParameter(String, OdbcType) |
初始化使用參數名稱與資料型態的類別新實例 OdbcParameter 。 |
屬性
| 名稱 | Description |
|---|---|
| DbType |
取得或設定參數的 。DbType |
| Direction |
取得或設定一個值,指示參數是僅輸入、僅輸出、雙向,或是儲存程序回傳值參數。 |
| IsNullable |
取得或設定一個值,指示參數是否接受空值。 |
| OdbcType |
取得或設定參數的 。OdbcType |
| ParameterName |
取得或設定 的名稱。OdbcParameter |
| Precision |
取得或設定用來表示 Value 該屬性的數字數。 |
| Scale |
取得或設定被解決的小 Value 數點數。 |
| Size |
取得或設定欄位內資料的最大大小。 |
| SourceColumn | |
| SourceColumnNullMapping |
取得或設定一個值,指示來源欄位是否可為空。 這讓 DbCommandBuilder 能夠正確地為可空欄位產生 Update 語句。 |
| SourceVersion |
當你載入Value時,會取得或設定DataRowVersion要使用的 。 |
| Value |
取得或設定參數的值。 |
方法
| 名稱 | Description |
|---|---|
| CreateObjRef(Type) |
建立一個物件,包含產生代理伺服器所需的所有相關資訊,用於與遠端物件通訊。 (繼承來源 MarshalByRefObject) |
| Equals(Object) |
判斷指定的 物件是否等於目前的物件。 (繼承來源 Object) |
| GetHashCode() |
做為預設雜湊函式。 (繼承來源 Object) |
| GetLifetimeService() |
取得目前控制此實例生命週期政策的終身服務物件。 (繼承來源 MarshalByRefObject) |
| GetType() |
取得目前實例的 Type。 (繼承來源 Object) |
| InitializeLifetimeService() |
取得一個終身服務物件以控制此實例的終身政策。 (繼承來源 MarshalByRefObject) |
| MemberwiseClone() |
建立目前 Object的淺層複本。 (繼承來源 Object) |
| MemberwiseClone(Boolean) |
建立一個 MarshalByRefObject 目前物件的淺層複製品。 (繼承來源 MarshalByRefObject) |
| ResetDbType() |
重置與此 OdbcParameter相關聯的型別。 |
| ResetOdbcType() |
重置與此 OdbcParameter相關聯的型別。 |
| ToString() |
得到包含 ParameterName的字串。 |
明確介面實作
| 名稱 | Description |
|---|---|
| ICloneable.Clone() |
關於此成員的描述,請參見 Clone()。 |
| IDbDataParameter.Precision |
表示數值參數的精度。 (繼承來源 DbParameter) |
| IDbDataParameter.Scale |
關於此成員的描述,請參見 Scale。 (繼承來源 DbParameter) |