다음을 통해 공유


OleDbParameter 클래스

OleDbCommand에 대한 매개 변수를 나타내고 DataSet 열에 대한 매개 변수의 매핑을 선택적으로 나타냅니다. 이 클래스는 상속될 수 없습니다.

네임스페이스: System.Data.OleDb
어셈블리: System.Data(system.data.dll)

구문

‘선언
Public NotInheritable Class OleDbParameter
    Inherits DbParameter
    Implements ICloneable, IDbDataParameter, IDataParameter
‘사용 방법
Dim instance As OleDbParameter
public sealed class OleDbParameter : DbParameter, ICloneable, IDbDataParameter, IDataParameter
public ref class OleDbParameter sealed : public DbParameter, ICloneable, IDbDataParameter, IDataParameter
public final class OleDbParameter extends DbParameter implements ICloneable, IDbDataParameter, 
    IDataParameter
public final class OleDbParameter extends DbParameter implements ICloneable, IDbDataParameter, 
    IDataParameter

설명

OLE DB .NET Framework Data Provider는 명명된 매개 변수 대신 물음표(?)로 표시된 위치 매개 변수를 사용합니다.

Microsoft OLE DB Provider for Oracle(MSDAORA) 및 OLE DB .NET Framework Data Provider를 사용하여 Oracle 데이터베이스를 쿼리할 때, LIKE 절을 사용하여 고정 길이의 필드에 있는 값을 쿼리하면 예상되는 모든 일치 항목이 반환되지 않을 수도 있습니다. Oracle에서는 LIKE 절을 사용하여 고정 길이 필드의 값을 찾을 때 뒤쪽 채움 공백을 포함하여 전체 문자열 길이가 일치하는 항목을 찾기 때문입니다. 예를 들어, Oracle 데이터베이스의 테이블에 char(3)으로 정의된 "Field1" 필드가 있고 해당 테이블의 행에 "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 "(고정 필드 길이 3이 되도록 "a"의 뒤쪽에 채움 공백 추가)로 저장하며, 고정 길이 필드에 대해 LIKE 비교를 수행할 때 이 값을 매개 변수 "a"와 일치하는 항목으로 처리하지 않기 때문입니다.

이 문제를 해결하려면 매개 변수 값에 백분율("%") 와일드카드 문자를 추가("a%")하거나 SQL = 비교를 대신 사용합니다.

예제

다음 예제에서는 OleDbDataAdapter 내에 있는 OleDbParameterCollection 컬렉션을 통해 OleDbParameter의 여러 인스턴스를 만듭니다. 이들 매개 변수는 데이터 소스에서 선택한 데이터를 DataSet에 배치하는 데 사용됩니다. 이 예제에서는 DataSetOleDbDataAdapter가 이미 적절한 스키마, 명령 및 연결을 사용하여 만들어져 있다고 간주합니다.

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.Object
   System.MarshalByRefObject
     System.Data.Common.DbParameter
      System.Data.OleDb.OleDbParameter

스레드로부터의 안전성

이 형식의 모든 public static(Visual Basic의 경우 Shared) 멤버는 스레드로부터 안전합니다. 인터페이스 멤버는 스레드로부터 안전하지 않습니다.

플랫폼

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에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.

버전 정보

.NET Framework

2.0, 1.1, 1.0에서 지원

참고 항목

참조

OleDbParameter 멤버
System.Data.OleDb 네임스페이스

기타 리소스

명령 사용