NET Support in Yukon


This code consists of C# and VB.NET versions in .NET for Yukon that illustrates the use of SqlPipe.

VB.NET Use SqlPipe in a .NET Stored Procedure
Listing 1 This simple stored procedure executes a parameterized query and returns the results through SqlPipe. You use the SqlContext class' static methods to obtain a SqlCommand instance in the current batch, then fill in parameters as you'd do with SqlClient. The SqlContext.GetPipe method obtains a pipe to the current TDS output stream.


' uses SqlDataReader and
' returns results via SqlPipe
_
Public Shared Sub getAuthorsByState( _
ByVal state As SqlString)

' get SqlCommand from context
Dim cmd As SqlCommand
cmd = SqlContext.GetCommand()

' set the text and parameters
cmd.CommandText = _
"select * from authors where state = _
@state"
cmd.Parameters.Add( _
"@state", SqlDbType.VarChar)
cmd.Parameters(0).Value = state

' call ExecuteReader
Dim rdr As SqlDataReader
rdr = cmd.ExecuteReader()

' send back the reader through SqlPipe
' SqlPipe is only available through context
Dim pipe As SqlPipe = SqlContext.GetPipe()
pipe.Send(rdr)
End Sub

****************c# sample**************************


using System;
using System.Data;
using System.Data.Sql;
using System.Data.SqlServer;
using System.Data.SqlTypes;

public class Procs
{
// uses SqlDataReader and returns results via SqlPipe
[SqlProcedure]
public static void getAuthorsByState(SqlString state)
{
SqlCommand cmd = SqlContext.GetCommand();
cmd.CommandText = "select * from authors where state = @state";
cmd.Parameters.Add("@state", SqlDbType.VarChar);
cmd.Parameters[0].Value = state;
SqlDataReader rdr = cmd.ExecuteReader();
SqlPipe pipe = SqlContext.GetPipe();
pipe.Send(rdr);
}
}

**********************************************************************
/////////////////////////////vb sample/////////////////////////////////////////

Imports System
Imports System.Data
Imports System.Data.Sql
Imports System.Data.SqlServer
Imports System.Data.SqlTypes

Public Class Procs

' uses SqlDataReader and returns results via SqlPipe
_
Public Shared Sub getAuthorsByState(ByVal state As SqlString)
Dim cmd As SqlCommand = SqlContext.GetCommand()
cmd.CommandText = "select * from authors where state = @state"
cmd.Parameters.Add("@state", SqlDbType.VarChar)
cmd.Parameters(0).Value = state
Dim rdr As SqlDataReader = cmd.ExecuteReader()
Dim pipe As SqlPipe = SqlContext.GetPipe()
pipe.Send(rdr)
End Sub
End Class


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: