Share via


SqlPipe.SendResultsStart(SqlDataRecord) メソッド

定義

クライアントに返す結果セットの先頭を宣言し、record パラメーターを使用して結果セットを表すメタデータを構築します。

public:
 void SendResultsStart(Microsoft::SqlServer::Server::SqlDataRecord ^ record);
public void SendResultsStart (Microsoft.SqlServer.Server.SqlDataRecord record);
member this.SendResultsStart : Microsoft.SqlServer.Server.SqlDataRecord -> unit
Public Sub SendResultsStart (record As SqlDataRecord)

パラメーター

record
SqlDataRecord

メタデータを抽出し、結果セットを記述するための SqlDataRecord オブジェクト。

例外

recordnull です。

record に列が含まれていないか、初期化されていません。

SendResultsRow(SqlDataRecord) メソッドの後で、SendResultsEnd()SendResultsStart(SqlDataRecord) のいずれにも該当しないメソッドが呼び出されました。

次の例では、新 SqlDataRecord しい とその を作成します SqlMetaData。 次に、 メソッドを使用して結果セットの先頭をマークし、 メソッドを使用してSendResultsStartSendResultsRowサンプル データを含むレコードをクライアントに送り返し、結果セットの末尾を メソッドでSendResultsEndマークします。

[Microsoft.SqlServer.Server.SqlProcedure]
public static void StoredProcReturnResultSet()
{
    // Create the record and specify the metadata for the columns.
    SqlDataRecord record = new SqlDataRecord(
        new SqlMetaData("col1", SqlDbType.NVarChar, 100),
        new SqlMetaData("col2", SqlDbType.Int));

    // Mark the begining of the result-set.
    SqlContext.Pipe.SendResultsStart(record);

    // Send 10 rows back to the client.
    for (int i = 0; i < 10; i++)
    {
        // Set values for each column in the row.
        record.SetString(0, "row " + i.ToString());
        record.SetInt32(1, i);

        // Send the row back to the client.
        SqlContext.Pipe.SendResultsRow(record);
    }

    // Mark the end of the result-set.
    SqlContext.Pipe.SendResultsEnd();
}
<Microsoft.SqlServer.Server.SqlProcedure()> _
Public Shared Sub StoredProcReturnResultSet()

    ' Create the record and specify the metadata for the columns.
    Dim record As New SqlDataRecord( _
        New SqlMetaData("col1", SqlDbType.NVarChar, 100), _
        New SqlMetaData("col2", SqlDbType.Int))

    ' Mark the begining of the result-set.
    SqlContext.Pipe.SendResultsStart(record)

    ' Send 10 rows back to the client.
    Dim i As Integer
    For i = 0 To 9

        ' Set values for each column in the row.
        record.SetString(0, "row " & i.ToString())
        record.SetInt32(1, i)

        ' Send the row back to the client.
        SqlContext.Pipe.SendResultsRow(record)
    Next

    ' Mark the end of the result-set.
    SqlContext.Pipe.SendResultsEnd()
End Sub

注釈

マネージド ストアド プロシージャは、 を実装していないクライアントに結果セットを SqlDataReader送信できます。 このメソッドは、 および とSendResultsEndSendResultsRowに、ストアド プロシージャがカスタム結果セットをクライアントに送信できるようにします。

メソッドは SendResultsStart 結果セットの先頭をマークし、record パラメーターを使用して、結果セットを記述するメタデータを構築します。 メソッドを使用して送信される後続のすべての行は SendResultsRow 、そのメタデータ定義と一致する必要があります。

を呼び出したSendResultsStart後は、 SendResultsEnd と のみをSendResultsRow呼び出すことができることに注意してください。 の同じインスタンス内の他の SqlPipe メソッドは、 を InvalidOperationExceptionスローします。 SendResultsEnd は、他のメソッドを呼び出すことができる初期状態に戻 SqlPipe します。

制御が CLR の実行から Transact-SQL に戻った後は、CLR メモリに初期化された静的変数またはローカル変数を使用しないでください。 たとえば、 のインスタンスをプロセス クラスに格納しないでください。これは SQLDataRecord、CLR から制御が返された後に使用されます。 例外の 1 つは、 SQLMetaData in process クラスです。

適用対象

こちらもご覧ください