ASP.NET
  Home arrow ASP.NET arrow Page 3 - More about Stored Procedures using ASP.NET...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ASP.NET

More about Stored Procedures using ASP.NET 2.0 with the Microsoft Data Access Application Block
By: Jagadish Chaterjee
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 17
    2006-10-30

    Table of Contents:
  • More about Stored Procedures using ASP.NET 2.0 with the Microsoft Data Access Application Block
  • Retrieving a RETURN value from a stored procedure using ASP.NET 2.0 and the Data Access Application Block
  • Retrieving a complete row from a stored procedure using ASP.NET 2.0 and the Data Access Application Block
  • Retrieving an OUTPUT parameter value from a stored procedure using ASP.NET 2.0 and the Data Access Application Block

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    More about Stored Procedures using ASP.NET 2.0 with the Microsoft Data Access Application Block - Retrieving a complete row from a stored procedure using ASP.NET 2.0 and the Data Access Application Block


    (Page 3 of 4 )

    In previous sections, we worked with only single values.  Now, in this section, we shall look into retrieving a complete row returned by a stored procedure.

    Before going to the code to execute a stored procedure, we need to create a simple stored procedure (with a single parameter) for this demonstration.  The following is the code for the stored procedure I created:

    CREATE PROCEDURE dbo.p_GetEmployee

          (

          @empno int

          )

    AS

          select * from emp where empno = @empno

          RETURN

    You can observe that the above stored procedure simply returns a complete row from the “emp” table based on the “empno” sent as parameter. 

    The following is the complete code needed to execute the above stored procedure using ASP.NET 2.0 through the Data Access Application Block

    ImportsSystem.Data

    ImportsMicrosoft.Practices.EnterpriseLibrary.Data.Sql

    ImportsMicrosoft.Practices.EnterpriseLibrary.Data

    PartialClass Sample3

        Inherits System.Web.UI.Page

        Protected Sub btnConnect_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnConnect.Click

            Try

                Dim dr As DataRow = SPExecute("p_GetEmployee", "1001")

                Me.lblMsg.Text = dr("ename") & ", " & dr("sal")

            Catch ex As Exception

                Me.lblMsg.Text = ex.Message

            End Try

        End Sub

        Private Function SPExecute(ByVal Name As String, ByVal empno As String) As DataRow

            Try

                Dim db As SqlDatabase = DirectCast(DatabaseFactory.CreateDatabase("AdventureWorks"), SqlDatabase)

                Dim ds As DataSet = db.ExecuteDataSet(Name, New Object() {empno})

                Return ds.Tables(0).Rows(0)

            Catch ex As Exception

                Throw New Exception("Unable to execute:" & ex.Message)

            End Try

        End Function

        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        End Sub

    EndClass

    Even though the above code works pretty well, not everyone likes the above methodology, because it works with dataset.  The other way to make this work is by using OUTPUT parameters.  The next section concentrates on this.

    More ASP.NET Articles
    More By Jagadish Chaterjee


       · Hello guys!I expanded the previous article on working with stored procedures...
       · This helped me a whole bunch! Thank you!
     

    ASP.NET ARTICLES

    - Adding Content to a Static ASP.NET Website
    - Building a Static ASP.NET Website in a Basic...
    - Develop Your First ASP.NET Website with Visu...
    - Run ASP.NET in Windows XP Home with Cassini ...
    - How to Test a Web Application
    - How to Add Code and Validation Controls to a...
    - Working in Source and Split Views to Build a...
    - How to Build a Web Form for a One-Page Web A...
    - How to Develop a One-Page Web Application
    - An ASP.NET Web Application in Action
    - Developing ASP.NET Web Applications
    - An Introduction to ASP.NET Web Programming
    - Introduction to the ADO.NET Entity Framework...
    - Completing an In-Text Advertising System und...
    - Programming an In-Text Advertising System un...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek