Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. Retrival of stored data from a table using asp.net 2.0

Retrival of stored data from a table using asp.net 2.0

Scheduled Pinned Locked Moved ASP.NET
csharpasp-net
5 Posts 3 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    brardavi
    wrote on last edited by
    #1

    How we can retrive the data from a table using asp.net 2.0

    S B 2 Replies Last reply
    0
    • B brardavi

      How we can retrive the data from a table using asp.net 2.0

      S Offline
      S Offline
      Sathesh Sakthivel
      wrote on last edited by
      #2

      The code sample above retrieves an entire record from a database table. Sometimes however we need only specific fields from a row in a database table. In this case we need to supply the stored procedure with not only an input parameter as in the previous section, but also one or more output parameters to store the result of the stored procedure. The following is an example of a stored procedure which will take as input the CustomerID value and return only two fields: CompanyName and ContactName. For this limited result set, we have to use the AddOutputParameter() method. This method is used to return the output of a stored procedure. It is recommended when executing a stored procedure with output parameters to use the ExecuteNonQuery() method instead of the ExecuteDataReader() method. The SQL stored procedure is as follows: CREATE PROCEDURE [dbo].[GetCustomerMultipleFields] ( @CustomerID NCHAR(5), @CompanyName NVARCHAR(40) OUTPUT, @ContactName NVARCHAR(30) OUTPUT ) AS SET NOCOUNT ON SELECT @CompanyName = [CompanyName], @ContactName = [ContactName] FROM [Customers] WHERE [CustomerID] LIKE @CustomerID GO The following C# code executes the above stored procedure and uses the AddOutputParameter() method to obtain the results: try { // Create DataBase Instance Database db = DatabaseFactory.CreateDatabase(); // Initialize the Stored Procedure DBCommandWrapper dbCommandWrapper = db.GetStoredProcCommandWrapper("GetCustomerMultipleFields"); dbCommandWrapper.AddInParameter("@CustomerID", DbType.String, "ALFKI"); dbCommandWrapper.AddOutParameter("@CompanyName", DbType.String, 40); dbCommandWrapper.AddOutParameter("@ContactName", DbType.String, 30); //Execute the stored procedure db.ExecuteNonQuery(dbCommandWrapper); //Display results of the query string results = string.Format("Company Name : {0}, Contact Name {1},", dbCommandWrapper.GetParameterValue("@CompanyName"), dbCommandWrapper.GetParameterValue("@ContactName")); Response.Write(results); } catch (Exception ex) { Response.Write(ex.ToString()); } In the above code, I passed a customer ID value to the stored procedure as an input parameter. As the stored procedure is designed to return two values, CompanyName and ContactName, these were identified as output parameters. To display the returned values we used another method of dbCommandWrapper, which is GetParameterValue(“ParameterName”).

      1 Reply Last reply
      0
      • B brardavi

        How we can retrive the data from a table using asp.net 2.0

        B Offline
        B Offline
        brardavi
        wrote on last edited by
        #3

        Kindly tell me some other way without using procedure

        S J 2 Replies Last reply
        0
        • B brardavi

          Kindly tell me some other way without using procedure

          S Offline
          S Offline
          Sathesh Sakthivel
          wrote on last edited by
          #4

          Using the Stored Procedure and query is the best method for retreiving the Data's from the table.

          With Regards Satips

          1 Reply Last reply
          0
          • B brardavi

            Kindly tell me some other way without using procedure

            J Offline
            J Offline
            Jay_se
            wrote on last edited by
            #5

            Hi there, + Pls Be Specific on your Question. Dont ask a question like (General) this. + Can you figure out, where u r getting problem on Retrieving Data from DataBase ? + You need to use SQLDataSource or ObjectDataSource or some one else to achieve this.

            Regards, Jay :)

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups