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 376969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T14:39:04+00:00 2026-05-12T14:39:04+00:00

In the below Stored procedure, i am returning a row if all the conditions

  • 0

In the below Stored procedure, i am returning a row if all the conditions satisfies, orelse i am returning a message like which condition is nor satisfied.
The Stored proc is working perfectly…

ALTER PROCEDURE dbo.BookingCheck
    (
    @int_duration_of_stay   int ,
    @int_number_of_guests   int,
    @date_of_application    date,
    @date_of_checkin        date,
    @date_of_checkout       date,
    @str_room_type          varchar(50),
    @ret_value              varchar(100) = '' output
    )
AS
    DECLARE @MaxPer int
    DECLARE @BasicCharge int
    DECLARE @SurCharge int
    DECLARE @TotalAmount int
    DECLARE @NoOfDays int
    DECLARE @Free VARCHAR(10)

    IF @int_duration_of_stay > 6
    BEGIN
        SET @NoOfDays = @int_duration_of_stay
        SET @Free = 'Yes'
    END 
    ELSE
    BEGIN
        SET @NoOfDays = @int_duration_of_stay - 1
        SET @Free = 'No'
    END


    SELECT @MaxPer = int_max_pax, @BasicCharge = flt_basic_charge, @SurCharge = flt_surcharge_per_pax 
    FROM RoomTypes WHERE UPPER(str_room_type) = UPPER(@str_room_type)

IF DATEDIFF(DAY, GETDATE(), @date_of_checkin) < 40
BEGIN
    IF @int_number_of_guests <= @MaxPer
    BEGIN
        SET @TotalAmount = (@NoOfDays * @int_number_of_guests * @SurCharge) + @BasicCharge
        SET @ret_value = 'Success'

        SELECT @str_room_type as 'Room Type', @MaxPer as 'Max Persons Allowed', @int_number_of_guests as 'No. of persons requested',  
        @int_duration_of_stay as 'No. of days stay', @BasicCharge as 'Basic Charge',  @SurCharge as 'Sur Charge', @Free as 'Complimentary',
         @TotalAmount as 'Total Amount'
    END
    ELSE
    BEGIN
        SET @ret_value = 'Max persons allowed is ' + CONVERT(VARCHAR(20), @MaxPer)
    END
END
ELSE
BEGIN
    SET @ret_value = 'The check in date should be less than 40 days from current date.'
END
RETURN

The problem is dont know how to get the return message or return row from the SP using c#.

The below code returns me the rows if the condition is satisfied in SP. if not, i am not getting the return message. How to get that ?

 public DataSet BookingCheck(int duration_of_stay, int number_of_guests,
    string date_of_application, string date_of_checkin, string date_of_checkout,
    string room_type)
{
    DataSet dsGetBookingCheck = new DataSet();
    SqlConnection conn = new SqlConnection(Con);
    SqlCommand command = new SqlCommand("BookingCheck", conn);
    command.CommandType = CommandType.StoredProcedure;
    SqlDataAdapter da = new SqlDataAdapter();
    SqlParameter param = new SqlParameter();
    param = command.Parameters.Add("@int_duration_of_stay", SqlDbType.Int);
    param.Value = duration_of_stay;
    param = command.Parameters.Add("@int_number_of_guests", SqlDbType.Int);
    param.Value = number_of_guests;
    param = command.Parameters.Add("@date_of_application", SqlDbType.Date);
    param.Value = date_of_application;
    param = command.Parameters.Add("@date_of_checkin", SqlDbType.Date);
    param.Value = date_of_checkin;
    param = command.Parameters.Add("@date_of_checkout", SqlDbType.Date);
    param.Value = date_of_checkout;
    param = command.Parameters.Add("@str_room_type", SqlDbType.VarChar, 50);
    param.Value = room_type;
    conn.Open();
    command.ExecuteNonQuery();
    da.SelectCommand = command;
    da.Fill(dsGetBookingCheck);
    conn.Close();
    return dsGetBookingCheck;
}
  • 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-05-12T14:39:04+00:00Added an answer on May 12, 2026 at 2:39 pm

    You need to add an out parameter:

    command.Parameters.Add("@ret_value", SqlDbType.String);
    command.Parameters["@ret_value"].Direction = ParameterDirection.Output;
    

    then after executing the SP

    message = command.Parameters["@ret_value"].Value.ToString();
    

    Here is function with out param:

     public DataSet BookingCheck(int duration_of_stay, int number_of_guests,
        string date_of_application, string date_of_checkin, string date_of_checkout,
        string room_type, out string message)
    {
        DataSet dsGetBookingCheck = new DataSet();
        SqlConnection conn = new SqlConnection(Con);
        SqlCommand command = new SqlCommand("BookingCheck", conn);
        command.CommandType = CommandType.StoredProcedure;
        SqlDataAdapter da = new SqlDataAdapter();
        SqlParameter param = new SqlParameter();
        param = command.Parameters.Add("@int_duration_of_stay", SqlDbType.Int);
        param.Value = duration_of_stay;
        param = command.Parameters.Add("@int_number_of_guests", SqlDbType.Int);
        param.Value = number_of_guests;
        param = command.Parameters.Add("@date_of_application", SqlDbType.Date);
        param.Value = date_of_application;
        param = command.Parameters.Add("@date_of_checkin", SqlDbType.Date);
        param.Value = date_of_checkin;
        param = command.Parameters.Add("@date_of_checkout", SqlDbType.Date);
        param.Value = date_of_checkout;
        param = command.Parameters.Add("@str_room_type", SqlDbType.VarChar, 50);
        param.Value = room_type;
        command.Parameters.Add("@ret_value", SqlDbType.String);
        command.Parameters["@ret_value"].Direction = ParameterDirection.Output;
        conn.Open();
        command.ExecuteNonQuery();
        da.SelectCommand = command;
        da.Fill(dsGetBookingCheck);
        message = command.Parameters["@ret_value"].Value.ToString();
        conn.Close();
        return dsGetBookingCheck;
    }
    

    NOTE: I have never done with with using ExecuteNonQuery and then using Fill on a data adapter. That might mess this up.

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

Sidebar

Related Questions

Below is my stored procedure. I want use stored procedure select all row of
my stored procedure is like below, select T.TranNo,(Select Accountname from Accountable where AccountCode =T.tranAccountCode)
I have a stored procedure which executes some dynamic sql, shown below. I've tried
The stored procedure below isn't catching the proper conditions. If I submit both images,
Below is stored procedure I have written which used nested cursor. create or replace
When i Fill all the data in the web form the below Stored procedure
I have a Select like the one below in a stored procedure (shortened for
I have written below stored procedure. In which i need to create Two Temporary
I have got the below stored procedure to return the list of Id, parentId
I am using the stored procedure below for the select command of a SqlDataSource,

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.