Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8289239
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:27:44+00:00 2026-06-08T12:27:44+00:00

I am returning 0 and 1 from a stored procedure like following. How can

  • 0

I am returning 0 and 1 from a stored procedure like following. How can I fetch it in c# asp.net file?

ALTER procedure [dbo].[crudprocedure] 

    @getusername        varchar(20),
    @getfirstname       varchar(20),
    @getlastname        varchar(20),
    @getaddress         varchar(20)
 as 
 begin
IF not exists (select username from crudtable where username=@getusername)
begin 
insert into crudtable(username,firstname,lastname,address) 
values (@getusername,@getfirstname,@getlastname,@getaddress)
return 0
end
else
return 1
end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T12:27:45+00:00Added an answer on June 8, 2026 at 12:27 pm

    If you’re using SQL Server – then try this code here:

    using (SqlConnection conn = new SqlConnection("...put your connection string here..."))
    using (SqlCommand cmd = new SqlCommand("dbo.crudprocedure", conn))
    {
       cmd.CommandType = CommandType.StoredProcedure;
    
       cmd.Parameters.Add("@getusername", SqlDbType.VarChar, 20).Value = "test";
       cmd.Parameters.Add("@getfirstname", SqlDbType.VarChar, 20).Value = "test";
       cmd.Parameters.Add("@getlastname", SqlDbType.VarChar, 20).Value = "test";
       cmd.Parameters.Add("@getaddress", SqlDbType.VarChar, 20).Value = "test";
    
       // define additional paramter of Direction = ReturnValue
       cmd.Parameters.Add("RETURN_VALUE", SqlDbType.Int).Direction = ParameterDirection.ReturnValue;
    
       // open connection, execute stored proc, close connection
       conn.Open();
       cmd.ExecuteNonQuery();
       conn.Close();
    
       // fetch the value of the "ReturnValue" parameter
       int returnValueInt = Convert.ToInt32(cmd.Parameters["RETURN_VALUE"].Value);
    }
    

    Basically, since you’re sending back that value using RETURN 1 from the stored procedure, you need to add an additional parameter to your SqlCommand object that has a .Direction of ParameterDirection.ReturnValue.

    That parameter will be set to the value that you send back from the stored procedure using RETURN ....

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using .Net and Oracle 11g - I've been returning dataTables from a procedure inside
Assume I have some stored procedure (and I can't change it) which is returning
I am returning a static string from a stored procedure (in SQL Server 2008)
I am returning XML from a stored procedure, that I want to capture in
I'm following Steve Sanderson's example from this ASP.NET MVC book on creating a model
My stored procedure is: ALTER PROCEDURE [dbo].[Insert_QuickLabDump] @Specimen_ID [varchar](50), @Client_Key int, @Outcome [varchar](50), @Medications
I have this store procedure... select a.IsDirectClient from dbo.Companies as a where a.SchemeName =
I created a stored procedure so as to return me a table. Something like
What I'm trying to do is take the results from a stored procedure and
In the below Stored procedure, i am returning a row if all the conditions

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.