Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
SqlDataRecord Class

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
SqlDataRecord Class

Represents a single row of data and its metadata. This class cannot be inherited.

Namespace:  Microsoft.SqlServer.Server
Assembly:  System.Data (in System.Data.dll)
Visual Basic (Declaration)
Public NotInheritable Class SqlDataRecord _
    Implements IDataRecord
Visual Basic (Usage)
Dim instance As SqlDataRecord
C#
public sealed class SqlDataRecord : IDataRecord
Visual C++
public ref class SqlDataRecord sealed : IDataRecord
JScript
public final class SqlDataRecord implements IDataRecord

This class is used together with SqlPipe to send result sets to the client from managed code stored-procedures.

When writing common language runtime (CLR) applications, you should re-use existing SqlDataRecord objects instead of creating new ones every time. Creating many new SqlDataRecord objects could severely deplete memory and adversely affect performance.

The following example shows how to create several SqlMetaData objects, which describe the column metadata of a record, and creating a SqlDataRecord. The column values of the SqlDataRecord are set and the SqlDataRecord is sent to the calling program by using the SqlContext class.

Visual Basic
<Microsoft.SqlServer.Server.SqlProcedure()> _
Public Shared Sub CreateNewRecord()

   ' 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() {New SqlMetaData("Column1", SqlDbType.NVarChar, 12), _
                                                 New SqlMetaData("Column2", SqlDbType.Int), _
                                                 New SqlMetaData("Column3", SqlDbType.DateTime)})

   ' Set the record fields.
   record.SetString(0, "Hello World!")
   record.SetInt32(1, 42)
   record.SetDateTime(2, DateTime.Now)

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

End Sub

C#
[Microsoft.SqlServer.Server.SqlProcedure]
public static void CreateNewRecord()
{

   // 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[] { new SqlMetaData("Column1", SqlDbType.NVarChar, 12), 
                                                  new SqlMetaData("Column2", SqlDbType.Int), 
                                                  new SqlMetaData("Column3", SqlDbType.DateTime) });

   // Set the record fields.
   record.SetString(0, "Hello World!");
   record.SetInt32(1, 42);
   record.SetDateTime(2, DateTime.Now);

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

System..::.Object
  Microsoft.SqlServer.Server..::.SqlDataRecord
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker