ASP.NET Code
  Home arrow ASP.NET Code arrow Return Value from Stored Procedure using ....
Iron Speed
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  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Download TestComplete 
Windows Web Hosting
 
IBM® developerWorks 
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 CODE

Return Value from Stored Procedure using .NET
By: aspfree
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 2 stars2 stars2 stars2 stars2 stars / 6
    2001-12-05

    Table of Contents:

    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
     
     
    Iron Speed
     
    ADVERTISEMENT

    Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!

    Return Value from Stored Procedure

    This tip uses ExecuteScalar to return a value from a stored procedure and increment the value by one.



    <%@ Page Language="VB" EnableSessionState="False" EnableViewState="False" 
    
    Trace="False"
    Debug="False" Strict="True" %>

    <%@ Import Namespace="System.Data" %>

    <%@ Import Namespace="System.Data.SQLClient" %>

    <script language="VB" runat="server">

    Sub Page_Load(Sender As Object, E As EventArgs)


    Dim myConnection As SqlConnection = _
    New SqlConnection(ConfigurationSettings.AppSettings("DSN"))

    Dim MyCommand as SQLCommand = New SQLCommand("spReturnarticleId", MyConnection)

    MyCommand.CommandType = CommandType.StoredProcedure


    myConnection.Open()


    'Execute the Stored Procedure, return the value and increment it by 1

    Dim count As Int32 = CInt(myCommand.ExecuteScalar()) + 1

    dim strID as string = cstr(count)


    'Set the value of a textbox

    text1.text = strId


    'Set the Value of a message to test what value is returned

    Message.InnerHtml = strId

    myConnection.Close()

    End Sub

    </script>

    <html>

    <head></head>

    <body>

    <h1 align="center">Article Info</h1>

    <span id="Message" style="font: arial 11pt;color:#339900;" runat="server"/></h2>

    <asp:textbox id="text1" size="20" runat="server" />

    </body>

    </html>

     

    Stored Proc code.

    CREATE PROCEDURE spReturnArticleID

    as

    SELECT max(articleId) FROM articleInfo

    RETURN

    GO

    Table Code

    CREATE TABLE [dbo].[articleInfo] (

    [articleId] [int] NOT NULL ,

    [catID] [int] NOT NULL,

    [typeID] [int] NOT NULL,

    [fpTitle] [varchar] (255),

    [fpMessage] [varchar] (8000),

    [titleOfDemo] [varchar] (255),

    [href] [varchar] (150),

    [demoLink] [varchar] (255),

    [downloadLink] [varchar] (255),

    [dateSubmitted] [datetime] NULL,

    [dateUpdated] [datetime] NULL,

    [authorId] [int] NULL,

    [active] [bit] NOT NULL,

    [pageHits] [int] NULL,

    [fileName] [varchar] (150),

    [filePath] [varchar] (50),

    [fileCreated] [datetime] NULL

    ) ON [PRIMARY]

    GO

    ALTER TABLE [dbo].[articleInfo] WITH NOCHECK ADD

    CONSTRAINT [DF_tblWhatsNew_new_Active] DEFAULT (1) FOR [active],

    CONSTRAINT [PK_tblWhatsNew_new] PRIMARY KEY NONCLUSTERED

    (

    [articleId]

    ) WITH FILLFACTOR = 90 ON [PRIMARY]

    GO

     

    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

    More ASP.NET Code Articles
    More By aspfree

     

    IBM® developerWorks developerWorks - FREE Tools!


    NEW! Building a grid system using WS-Resource Transfer, Part 4: Using WS-RT for grid monitoring

    In this five-part "Building a grid system using WS-Resource Transfer" series, we look at the use of WS-Resource Transfer (WS-RT) in different areas of the grid environment -- from using it as a method for storing and recovering general information about grid-to-grid monitoring and management, and security. We also examine how WS-RT can be used for the distribution and division of work. In any grid, there is a huge amount of metadata about the grid that needs to be stored and distributed. Using WS-RT makes sharing the information, especially the precise information required by different systems in the grid, significantly easier. Here in Part 4, we look at both sides of the security session, both in terms of using WS-RT as an aid to the authorization process and at combining WS-Security with WS-RT for secure resource exchange.
    FREE! Go There Now!


    NEW! Cook up Web sites fast with CakePHP, Part 2: Bake bigger and better with CakePHP

    CakePHP is a stable production-ready, rapid-development aid for building Web sites in PHP. This "Cook up Web sites fast with CakePHP" series shows you how to build an online product catalog using CakePHP.
    FREE! Go There Now!


    NEW! Develop with Java and PHP technology on AIX Version 5.3, Part 6: Building the Java business application

    Set up a PHP Web interface for the Java(TM) business application using a database created in earlier in this series. The PHP Web interface collects information from users and sends the session data to the Java business application for processing and for a response.
    FREE! Go There Now!


    NEW! Hello World: Monitor a simple business process using WebSphere Business Monitor V6.0.2

    This tutorial shows new users of IBM WebSphere Business Monitor Version 6.0.2 how to perform the "Hello World" equivalent for monitoring business process applications. It is intended to help you get familiar with the capabilities of the product.
    FREE! Go There Now!


    NEW! IBM Rational Systems Development e-Kit

    As systems increase in complexity, communication between systems and software teams becomes more and more difficult. Now, there’s a way to improve product quality and communication.<br />Read the “Model Driven Systems Development” white paper to see how. Also included in this kit are more educational white papers, customer examples, tutorials, informative Webcasts, and best practices for designing, building and managing systems.<br />
    FREE! Go There Now!


    NEW! Krugle, developerWorks, and code search

    Ken Krugler, co-founder of code search company Krugle, and Laura Merling, vice president of Marketing and Business Development for Krugle, join to talk about the ins and outs of code search and what it means as a new feature for developerWorks users.
    FREE! Go There Now!


    NEW! Rational Modeling Extension for Microsoft.Net

    Rational Modeling Extension for Microsoft .NET enhances usability for code generation supporting a more intelligent refactoring. The latest enhancements enable organizations with Java and .NET systems and software development maintain architectural integrity across heterogeneous platforms.
    FREE! Go There Now!


    NEW! Run your first CICS application on a PC using TXSeries for Windows

    Learn the basics of the IBM Customer Information Control System (CICS). With a hands-on exercise, learn how to get your first CICS application up and running on your desktop using TXSeries V6.1 for Windows. The tutorial shows you how to download and install a free trial version of TXSeries V6.1.
    FREE! Go There Now!


    NEW! Webcast: Introducing the new Information Server and Solutions community: LeverageInformation

    User communities play an important role in communication and collaboration around products, solutions and other areas of special interest to members. Successful communities are able to provide the right mix of content and services to deliver a value proposition that resonates with each audience. Join Tom Inman, VP of Marketing for Information and Platform Solutions as he introduces the new LeverageINFORMATION community. During this webcast, learn about the value provided by the community and how customers and partners derive value from the community in addressing their own technical and business challenges.
    FREE! Go There Now!


    NEW! Webcast: What is new in Viper 2 for developers?

    Viper 2 brings a great value to developer communities including SQL, XML, PHP, Ruby, .NET and Java. You probably already know that DB2 Express-C is free for developers to develop, deploy and distribute. Viper 2 provides a variety of means that help move your application from the development stage to deployment more rapidly. This webcast shows how to best utilize the latest tools available for developing DB2 applications.
    FREE! Go There Now!



    All FREE IBM® developerWorks Tools!

    ASP.NET CODE ARTICLES

    - How to Use the ListBox Control in ASP.NET 2.0
    - How to Load XML Documents in ASP.NET 2.0
    - DataGrid Code
    - ASP.NET Guestbook
    - User Controls and Client Side Scripting
    - ASP.NET Programming with Microsoft's AS...
    - ASP.NET Basics (part 3): Hard Choices
    - ASP.NET Basics (part 2): Not My Type
    - ASP.NET Basics (part 1): Nothing But .Net
    - Directory Tree Browser
    - How to get the confirmation of Yes/No from a...
    - Complete example using custom errors and wri...
    - Paging Certain # records per page .NET style
    - General Methods of formatting and Subtractin...
    - .NET LinkButton web control

     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway