asp.net web forms C# , display stored procedure result on label

Hi experts,

I saw this example:

ex1.PNG
How to return Output parameter from Stored Procedure in ASP.Net using C# and VB.Net
https://www.aspsnippets.com/Articles/How-to-return-Output-parameter-from-Stored-Procedure-in-ASPNet-in-C-and-VBNet.aspx

In that example which he gives the sql server and asp.net code.

He has a stored procedures that looks like this:

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[GetFruitName]
      @FruitId INT,
      @FruitName VARCHAR(30) OUTPUT
AS
BEGIN
      SET NOCOUNT ON;
     
      SELECT @FruitName = FruitName
      FROM Fruits
      WHERE FruitId = @FruitId
END

Open in new window



How would I revise that exact same example.
If my stored procedure looked like this.
I just want to display the name of the fruit on the label of the asp.net page for whatever fruitid i submitted in the textbox.

USE [FruitsDB]
GO

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[GetFruitNameTest1]
	@FruitId INT

AS
BEGIN
	SET NOCOUNT ON;
	
    SELECT [FruitId]
          ,[FruitName]
    FROM [FruitsDB].[dbo].[Fruits]
	WHERE FruitId = @FruitId
END

GO

Open in new window

LVL 1
maqskywalkerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Kyle AbrahamsSenior .Net DeveloperCommented:
Instead of cmd.ExecuteNonQuery();

SqlDataReader dr = new SqlDataReader();
dr = cmd.ExecuteReader();

if (dr.HasRows)
{
   if (dr.Read())
     lblFruitName.Text = "Fruit Name: " + dr["FruitName"].ToString();
}

Open in new window


You can also review this for reference:
http://www.dotnetcodecentral.com/Post/56/ado-net-querying-for-data/retrieve-a-row-using-sqldatareader-in-ado-net
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
maqskywalkerAuthor Commented:
thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.