共用方式為


SqlDataRecord 物件

SqlDataRecord 物件表示資料的單一資料列及其相關的中繼資料。

Managed 預存程序可將不是來自 SqlDataReader 的結果集傳送給用戶端。 SqlDataRecord 類別以及 SqlPipe 物件的 SendResultsStart、SendResultsRow 及 SendResultsEnd 方法允許預存程序將自訂結果集傳送至用戶端。

如需詳細資訊,請參閱 .NET Framework SDK 文件集中的 Microsoft.SqlServer.Server.SqlDataRecord 類別參考文件集。

範例

以下範例會建立一筆新的員工記錄,並將它傳回給呼叫端。

C#

[Microsoft.SqlServer.Server.SqlProcedure]
public static void CreateNewRecordProc()
{
    // Variables.       
    SqlDataRecord record;

    // Create a new record with the column metadata.  The constructor 
    // is able to accept a variable number of parameters.
    record = new SqlDataRecord(new SqlMetaData("EmployeeID", SqlDbType.Int),
                               new SqlMetaData("Surname", SqlDbType.NVarChar, 20),
                               new SqlMetaData("GivenName", SqlDbType.NVarChar, 20),
                               new SqlMetaData("StartDate", SqlDbType.DateTime) );

    // Set the record fields.
    record.SetInt32(0, 0042);
    record.SetString(1, "Funk");
    record.SetString(2, "Don");
    record.SetDateTime(3, new DateTime(2005, 7, 17));

    // Send the record to the calling program.
    SqlContext.Pipe.Send(record);

}

Visual Basic

<Microsoft.SqlServer.Server.SqlProcedure()> _
Public Shared Sub  CreateNewRecordVBProc ()
    ' Variables.
    Dim record As SqlDataRecord

    ' Create a new record with the column metadata. The constructor is 
    ' able to accept a variable number of parameters

    record = New SqlDataRecord(New SqlMetaData("EmployeeID", SqlDbType.Int), _
                           New SqlMetaData("Surname", SqlDbType.NVarChar, 20), _
                           New SqlMetaData("GivenName", SqlDbType.NVarChar, 20), _
                           New SqlMetaData("StartDate", SqlDbType.DateTime))

    ' Set the record fields.
    record.SetInt32(0, 42)
    record.SetString(1, "Funk")
    record.SetString(2, "Don")
    record.SetDateTime(3, New DateTime(2005, 7, 17))

    ' Send the record to the calling program.
    SqlContext.Pipe.Send(record)

End Sub

請參閱

概念

SqlPipe 物件