Resources » .NET programming » .NET Framework

NET Support in Yukon


Posted Date: 02-Oct-2004  Last Updated:   Category: .NET Framework    
Author: Member Level: Bronze    Points: 5


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


Did you like this resource? Share it with your friends and show your love!

Responses to "NET Support in Yukon"

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

Feedbacks      

Post 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:   Sign In to fill automatically.
    Email: (Will not be published, but required to validate comment)



    Type the numbers and letters shown on the left.


    Submit Article     Return to Article Index

    Subscribe to Subscribers
    Awards & Gifts
    Talk to Webmaster Tony John

    Online Members

    amit
    chuckchen
    More...
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India