OleDbParameter クラス
アセンブリ: System.Data (system.data.dll 内)

Public NotInheritable Class OleDbParameter Inherits DbParameter Implements ICloneable, IDbDataParameter, IDataParameter
public ref class OleDbParameter sealed : public DbParameter, ICloneable, IDbDataParameter, IDataParameter

OLE DB .NET Framework データ プロバイダでは、名前付きパラメータではなく、疑問符 (?) で示される位置指定パラメータが使用されます。
Microsoft OLE DB Provider for Oracle (MSDAORA) と OLE DB .NET Framework データ プロバイダを使用して Oracle データベースに対するクエリを実行する場合、LIKE 句を使用して固定長フィールドの値を問い合わせると、期待される一致したデータがすべて返されないことがあります。これは、Oracle によって LIKE 句の固定長フィールドの値との比較が行われるときに、末尾の空白を含めて、文字列の全長にわたって比較が行われるからです。たとえば、Oracle データベースのテーブルに char(3) として定義されている "Field1" という名前のフィールドが存在し、そのテーブルの行の 1 つに "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 では、3 の固定長に合わせるために "a" に続けて空白を埋めて、列値を "a " として格納しているからです。Oracle は、固定長フィールドの LIKE 比較において、これをパラメータ値 "a" と一致しているとは見なしません。
この問題を解決するには、パーセント ("%") ワイルドカード文字をパラメータ値 ("a%") に追加するか、または代わりに SQL = 比較を使用します。

OleDbDataAdapter の OleDbParameterCollection コレクションを使用して、OleDbParameter の複数のインスタンスを作成する例を次に示します。これらのパラメータは、データ ソースからのデータの選択と、DataSet でのデータの配置に使用されます。この例は、DataSet および OleDbDataAdapter が、正しいスキーマ、コマンド、および接続で既に作成されていることを前提にしています。
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
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; }
using System; using System.Data; using System.Data.OleDb; class Class1 { static void Main() { // string x = "Provider=SQLOLEDB;Data Source=(local);Integrated Security=SSPI;Initial Catalog=Northwind"; } 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; }

System.MarshalByRefObject
System.Data.Common.DbParameter
System.Data.OleDb.OleDbParameter


Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からOleDbParameter クラスを検索する場合は、下記のリンクをクリックしてください。

- OleDbParameter クラスのページへのリンク