SqlDataRecord 物件
適用於:SQL Server
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