IDbCommand.Prepare 메서드

정의

데이터 소스에 대해 명령의 준비된(또는 컴파일된) 버전을 만듭니다.

public:
 void Prepare();
public void Prepare ();
abstract member Prepare : unit -> unit
Public Sub Prepare ()

예외

Connection이 설정되지 않은 경우

또는

ConnectionOpen()이 아닌 경우

예제

다음 예제에서는 파생 클래스OleDbCommand의 instance 만들고 연결을 엽니다. 그런 다음, SQL Select 문인 문자열과 데이터 원본에 연결하는 데 사용할 문자열을 전달하여 데이터 원본에 저장 프로시저를 준비합니다.

private static void OleDbCommandPrepare(string connectionString)
{
    using (OleDbConnection connection = new
               OleDbConnection(connectionString))
    {
        connection.Open();

        // Create the Command.
        OleDbCommand command = new OleDbCommand();

        // Set the Connection, CommandText and Parameters.
        command.Connection = connection;
        command.CommandText =
            "INSERT INTO dbo.Region (RegionID, RegionDescription) VALUES (?, ?)";
        command.Parameters.Add("RegionID", OleDbType.Integer, 4);
        command.Parameters.Add("RegionDescription", OleDbType.VarWChar, 50);
        command.Parameters[0].Value = 20;
        command.Parameters[1].Value = "First Region";

        // Call  Prepare and ExecuteNonQuery.
        command.Prepare();
        command.ExecuteNonQuery();

        // Change parameter values and call ExecuteNonQuery.
        command.Parameters[0].Value = 21;
        command.Parameters[1].Value = "SecondRegion";
        command.ExecuteNonQuery();
    }
}
Public Sub OleDbCommandPrepare(ByVal connectionString As String)

    Using connection As OleDbConnection = New _
        OleDbConnection(connectionString)
        connection.Open()

        ' Create the Command.
        Dim command As New OleDbCommand()

        ' Set the Connection, CommandText and Parameters.
        command.Connection = connection
        command.CommandText = _
          "INSERT INTO dbo.Region (RegionID, RegionDescription) VALUES (?, ?);"
        command.Parameters.Add("RegionID", OleDbType.Integer, 4)
        command.Parameters.Add("RegionDescription", OleDbType.VarWChar, 50)
        command.Parameters(0).Value = 20
        command.Parameters(1).Value = "First Region"

        ' Call  Prepare and ExecuteNonQuery.
        command.Prepare()
        command.ExecuteNonQuery()

        ' Change parameter values and call ExecuteNonQuery.
        command.Parameters(0).Value = 21
        command.Parameters(1).Value = "Second Region"
        command.ExecuteNonQuery()
    End Using
End Sub

설명

속성이 로 CommandType 설정된 TableDirectPrepare 경우 아무 것도 수행하지 않습니다. 가 로 StoredProcedure설정된 경우 CommandType 에 대한 Prepare 호출은 성공해야 하지만 no-op이 발생할 수 있습니다. 서버에서 자동으로 다시 사용할 수 있도록 필요에 따라 계획 캐시 따라서 클라이언트 애플리케이션에서 직접이 메서드를 호출할 필요가 없습니다 있습니다.

적용 대상