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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:37:02+00:00 2026-06-11T20:37:02+00:00

I’m having a problem counting data w/ inner join. I want to count how

  • 0

I’m having a problem counting data w/ inner join.

I want to count how many cottages are available, here are my tables:

enter image description here

enter image description here

here’s my code in class getting the cottage number.

public void CheckCottages()
 {
     con.Close();
     SqlCommand comUmbrella = new SqlCommand("CountCottages", con);
     comUmbrella.CommandType = CommandType.StoredProcedure;
     comUmbrella.Parameters.Add("@CottageType", SqlDbType.NVarChar).Value = "Umbrella";
     comUmbrella.Parameters.Add("@ReservedDate", SqlDbType.DateTime).Value = this.ARRIVAL;
     con.Open();
     comUmbrella.ExecuteNonQuery();
     drUmbrella = comUmbrella.ExecuteReader();
     if (drUmbrella.Read())
     {
         this.UMBRELLA = drUmbrella.GetInt32(drUmbrella.GetOrdinal("Rows"));
     }
     con.Close();
     SqlCommand comNativeKubo = new SqlCommand("CountCottages", con);
     comNativeKubo.CommandType = CommandType.StoredProcedure;
     comNativeKubo.Parameters.Add("@CottageType", SqlDbType.NVarChar).Value = "Native Kubo";
     comNativeKubo.Parameters.Add("@ReservedDate", SqlDbType.DateTime).Value = this.ARRIVAL;
     con.Open();
     comNativeKubo.ExecuteNonQuery();
     drKubo = comNativeKubo.ExecuteReader();
     if (drKubo.Read())
     {
         this.NATIVEKUBO = drKubo.GetInt32(drKubo.GetOrdinal("Rows"));
     }
     con.Close();
     SqlCommand comTreeHouse = new SqlCommand("CountCottages", con);
     comTreeHouse.CommandType = CommandType.StoredProcedure;
     comTreeHouse.Parameters.Add("@CottageType", SqlDbType.NVarChar).Value = "Tree house";
     comTreeHouse.Parameters.Add("@ReservedDate", SqlDbType.DateTime).Value = this.ARRIVAL;
     con.Open();
     comTreeHouse.ExecuteNonQuery();
     drTree = comTreeHouse.ExecuteReader();
     if (drTree.Read())
     {
         this.TREEHOUSE = drTree.GetInt32(drTree.GetOrdinal("Rows"));
     }
     con.Close();
     SqlCommand comPavillion = new SqlCommand("CountCottages", con);
     comPavillion.CommandType = CommandType.StoredProcedure;
     comPavillion.Parameters.Add("@CottageType", SqlDbType.NVarChar).Value = "Pavillion";
     comPavillion.Parameters.Add("@ReservedDate", SqlDbType.DateTime).Value = this.ARRIVAL;
     con.Open();
     comPavillion.ExecuteNonQuery();
     drPavillion = comPavillion.ExecuteReader();
     if (drPavillion.Read())
     {
         this.PAVILLION = drPavillion.GetInt32(drPavillion.GetOrdinal("Rows"));
     }
 }

Here’s my stored Procedure:

ALTER PROCEDURE dbo.CountCottages
(
    @CottageType nvarchar(50),
    @ReservedDate datetime
)

AS
SELECT count(dbo.Cottages.CottageName)
FROM dbo.Cottages INNER JOIN
dbo.ResortTransactions ON dbo.Cottages.CottageID = dbo.ResortTransactions.CottageID
where dbo.Cottages.CottageType=@CottageType and dbo.ResortTransactions.Status != 'Cancelled' and dbo.ResortTransactions.ReservedDate != @ReservedDate

RETURN

What’s wrong to my code? I hope someone can help me 🙂

Thanks in advance!

  • 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-11T20:37:03+00:00Added an answer on June 11, 2026 at 8:37 pm

    Since there’s not much information about how your data is used, here’s a guess. I’m assuming you want a count of cottages where there is a transaction where 1) the status is not cancelled and 2) the date is equal to the reservation date. If so here’s the query:

    SELECT count(dbo.Cottages.CottageName)
        FROM dbo.Cottages 
        WERE CottageType=@CottageType 
            AND CottageID NOT IN
            (SELECT CottageID FROM dbo.ResortTransactions
             WHERE Status != 'Cancelled' 
             AND ReservedDate = @ReservedDate)
    

    Also you are executing the sproc twice – once using ExecuteNonQuery and once using ExecuteReader You should either return a value and use ExecuteNonQuery, creating a parameter to store the return value, or use ExecuteScalar to quickly pull the first result from the dataset.

    I would suggest reading up more on basic SQL and how to execute queries with .NET.

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

Sidebar

Related Questions

I want to count how many characters a certain string has in PHP, but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to construct a data frame in an Rcpp function, but when I
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I would like to count the length of a string with PHP. The string
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

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.