Help Complete This CLR Code?

Using the tutorial at:

http://msdn2.microsoft.com/en-us/library/ms131094.aspx

I've determined that the code I need to follow is:

Imports System
Imports System.Data
Imports System.Data.Sql
Imports System.Data.SqlTypes
Imports Microsoft.SqlServer.Server
Imports System.Data.SqlClient

'The Partial modifier is only required on one class definition per project.
Partial Public Class StoredProcedures
''' <summary>
''' Create a result set on the fly and send it to the client.
''' </summary>
<Microsoft.SqlServer.Server.SqlProcedure> _
Public Shared Sub SendTransientResultSet()
' Create a record object that represents an individual row, including it's metadata.
Dim record As New SqlDataRecord(New SqlMetaData("stringcol", SqlDbType.NVarChar, 128) )

' Populate the record.
record.SetSqlString(0, "Hello World!")

' Send the record to the client.
SqlContext.Pipe.Send(record)
End Sub
End Class

Given this code, how do I add other SqlMetaData Columns to the statement:

Dim record As New SqlDataRecord(New SqlMetaData("stringcol", SqlDbType.NVarChar, 128) )

---

Like this

Dim record As New SqlDataRecord(New SqlMetaData("stringcol", SqlDbType.NVarChar, 128),New SqlMetaData("otherstringcol", SqlDbType.NVarChar, 128) )

I assume

record.SetSqlString(0, "Hello World!")

record.SetSqlString(1, "I'm Here!")

To populate the data.

Thanks,

-David



Answer this question

Help Complete This CLR Code?

  • skumar

    Ahhh crud. See I shoulda looked first, hope this helps someone.

    http://msdn2.microsoft.com/en-us/library/ms131105.aspx

    <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

  • Help Complete This CLR Code?