ASP.NET
  Home arrow ASP.NET arrow Page 5 - Working with Stored Procedures using ASP.N...
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

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

    Table of Contents:
  • Working with Stored Procedures using ASP.NET 2.0 with Microsoft Data Access Application Block
  • Executing a stored procedure from ASP.NET 2.0 using the Data Access Application Block
  • Executing a stored procedure with parameters from ASP.NET 2.0 using the Data Access Application Block
  • Executing a stored procedure with parameters from ASP.NET 2.0 using the
  • Executing a stored procedure with parameters from ASP.NET 2.0 using the Data Access Application Block: the recommended approach
  • Executing a stored procedure which returns a set of rows 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


    Working with Stored Procedures using ASP.NET 2.0 with Microsoft Data Access Application Block - Executing a stored procedure with parameters from ASP.NET 2.0 using the Data Access Application Block: the recommended approach


    (Page 5 of 6 )

    In this section, we shall modify the code given in the previous section to make it more readable and efficient.  In this part, we will be dealing with the Data Access Application Block to add parameters (input parameters).

    I shall use the same stored procedure given in the previous section.  The following is the complete modified code to execute the same stored procedure:

    ImportsSystem.Data

    ImportsMicrosoft.Practices.EnterpriseLibrary.Data.Sql

    ImportsMicrosoft.Practices.EnterpriseLibrary.Data

    PartialClass Sample2

        Inherits System.Web.UI.Page

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

            Try

                Me.lblMsg.Text = SPExecute("p_IncEmployeeSal", 1001) & " rows affected"

            Catch ex As Exception

                Me.lblMsg.Text = ex.Message

            End Try

        End Sub

        Private Function SPExecute(ByVal Name As String, ByVal ParamValue As Integer) As Integer

            Try

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

                Dim cmd As Common.DbCommand = db.GetStoredProcCommand(Name)

                db.AddInParameter(cmd, "Empno", DbType.Int32, ParamValue)

                Dim RowsAffected As Integer = db.ExecuteNonQuery(cmd)

            Catch ex As Exception

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

            End Try

        End Function

    EndClass

    More ASP.NET Articles
    More By Jagadish Chaterjee


       · Hello guys! This article shows you how to work with stored procedures using data...
       · You have explained everything except for one. You have explained how to retrieve the...
     

    ASP.NET ARTICLES

    - More Advanced ASP.NET 3.5 Functions and Subr...
    - ASP.NET 3.5 Functions and Subroutines
    - Coding an IQ Test with Conditionally Driven ...
    - Developing Conditionally Driven Event Handle...
    - ASP.NET 3.5 Debugging Using Visual Web Devel...
    - Understanding Event Handlers in ASP.NET 3.5
    - Building a Web Form in ASP.NET and PHP: a Co...
    - Inserting Data into a Microsoft SQL 2008 Dat...
    - Creating an ASP.NET Dynamic Web Page Using M...
    - Retrieving Data from Microsoft SQL Server 20...
    - Building ASP.NET Web Forms to Use a MySQL Da...
    - Creating an ASP.NET Database using MS SQL 20...
    - Building an ASP.NET Website Using Include Ta...
    - Create ASP.NET Web Forms to Use a Microsoft ...
    - Editing Web Design Layout in Visual Web Deve...





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