SqlPipe.SendResultsStart メソッド
アセンブリ: System.Data (system.data.dll 内)



マネージ ストアド プロシージャは、SqlDataReader を実装していないクライアントに対して結果セットを送信できます。このメソッドを、SendResultsRow および SendResultsEnd と組み合わせて使用することで、ストアド プロシージャからクライアントに対し、カスタムの結果セットを送信できます。
SendResultsStart メソッドは、結果セットの先頭を宣言するほか、結果セットを表すメタデータを、record パラメータを使って構築します。それ以降、SendResultsRow メソッドで送信するすべての行は、そのメタデータ定義と一致していることが必要です。
SendResultsStart を呼び出した後、続けて呼び出すことができるのは SendResultsRow および SendResultsEnd だけです。これら以外のメソッドを SqlPipe の同じインスタンスで呼び出した場合は、InvalidOperationException がスローされます。SendResultsEnd により SqlPipe が初期状態に戻され、再び他のメソッドを呼び出すことができるようになります。

次の例では、新しい SqlDataRecord と、その SqlMetaData オブジェクトを作成します。さらに、SendResultsStart メソッドで結果セットの先頭を宣言し、サンプルのデータを含むレコードを、SendResultsRow メソッドでクライアントに返した後、結果セットの最後に到達したことを、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
[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(); }

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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- SqlPipe.SendResultsStart メソッドのページへのリンク