SqlPipe.SendResultsRow(SqlDataRecord) Methode

Definition

Sendet eine einzelne Datenzeile an den Client zurück.

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

Parameter

record
SqlDataRecord

Ein SqlDataRecord-Objekt mit den Spaltenwerten für die Zeile, die an den Client gesendet werden sollen. Das Schema für den Datensatz muss mit dem Schema in den Metadaten des an die SqlDataRecord-Methode übergebenen SendResultsStart(SqlDataRecord) übereinstimmen.

Ausnahmen

record ist null.

Die SendResultsStart(SqlDataRecord)-Methode wurde zuvor nicht aufgerufen.

Beispiele

Im folgenden Beispiel werden ein neues SqlDataRecord und dessen SqlMetaDataerstellt. Das Beispiel markiert dann den Anfang eines Resultsets mithilfe der SendResultsStart -Methode, sendet Datensätze mit Beispieldaten mithilfe der SendResultsRow -Methode zurück an den Client und markiert das Ende des Resultsets mit der SendResultsEnd -Methode.

[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

Hinweise

Verwaltete gespeicherte Prozeduren können Resultsets an Clients senden, die keine implementieren SqlDataReader. Mit dieser Methode und SendResultsStartSendResultsEndkönnen gespeicherte Prozeduren benutzerdefinierte Resultsets an den Client senden.

Die SendResultsRow -Methode sendet eine einzelne Datenzeile zurück an den Client. Zeilen können anschließend an den Aufrufer zurückgegeben werden, indem für jede gesendete Zeile einmal aufgerufen SendResultsRowwird. Nachdem alle Zeilen gesendet wurden, ist ein Aufruf der SendResultsEnd -Methode erforderlich, um das Ende des Resultsets zu markieren.

Gilt für:

Weitere Informationen