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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:35:48+00:00 2026-05-27T22:35:48+00:00

How do I properly declair a parameter in the code below. Im getting underlines

  • 0

How do I properly declair a parameter in the code below. Im getting underlines on “SelectCommand” Im not sure what im doing wrong.

 public int GetTotalNumberOfAprovedPictureIds(string SexType)
    {
        string strConectionString = ConfigurationManager.AppSettings["DataBaseConnection"];

        SqlConnection conn = new SqlConnection(strConectionString);
        conn.Open();
        SqlCommand oCommand = new SqlCommand("SELECT COUNT(1) AS Expr1 FROM MEMBERS INNER JOIN Picture ON MEMBERS.MemberID = Picture.MemberID WHERE (Picture.PicAproval = 1) AND (Picture.PicArchive = 0) AND (MEMBERS.MemberSex = @dSexType)", conn);


        object oValue = oCommand.ExecuteScalar();

        oCommand.SelectCommand.Parameters.Add("@dSexType", SqlDbType.Text);
        oCommand.SelectCommand.Parameters["@dSexType"].Value = SexType;

        conn.Close();

        if (oValue == DBNull.Value)
        {
            return 0;
        }
        else
        {
            return Convert.ToInt32(oValue);
        }

    }
  • 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-27T22:35:48+00:00Added an answer on May 27, 2026 at 10:35 pm

    You are doing a couple of things wrong;

    1) You are adding the parameter AFTER you execute the query

    2) You are using the SelectCommand property when you don’t need to. In fact, you are probably confusing this with a DataAdapter object, which does have a SelectCommand property.

    Instead, try:

        public int GetTotalNumberOfAprovedPictureIds(string SexType)
        {
            string strConectionString = ConfigurationManager.AppSettings["DataBaseConnection"];
    
            using (SqlConnection conn = new SqlConnection(strConectionString))
            {
                conn.Open();
                using (SqlCommand oCommand = new SqlCommand("SELECT COUNT(*) FROM MEMBERS INNER JOIN Picture ON MEMBERS.MemberID = Picture.MemberID WHERE (Picture.PicAproval = 1) AND (Picture.PicArchive = 0) AND (MEMBERS.MemberSex = @dSexType)", conn))
                {
                    oCommand.CommandType = CommandType.Text;
                    SqlParameter myParam = oCommand.Parameters.Add("@dSexType", SqlDbType.Text);
                    myParam.Value = SexType;
    
                    object oValue = oCommand.ExecuteScalar();
    
                    if (oValue == DBNull.Value)
                    {
                        return 0;
                    }
                    else
                    {
                        return Convert.ToInt32(oValue);
                    }
                }
            }
    
        }
    

    I’d strongly urge you to use a “USING” statement when dealing with SqlConnection, SqlCommand and similar objects. It will ensure your connection is closed and disposed as soon as it leaves the scope, including after an exception.

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

Sidebar

Related Questions

Video not working properly in the below mentioned code. What could be the problem
Below code is validating properly.When i first submit the form,it shows the error message,second
Not sure how to properly formulate the question, there is a problem with currying
The following code executes properly when the data key has no data to send,
I am able to properly pass a string variable to the gqlquery through parameter
PHPUnit seems to execute properly (appropriate tests are executed & pass), but during code
texture is not loading properly it has lines and it is backwards. what is
JStree is not working properly with IE9. You can check this in their demo
This code works properly in my localhost. I am using xampp 1.7.3. but when
following code works properly but it applies same cell text to all sections. How

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.