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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T11:56:19+00:00 2026-06-03T11:56:19+00:00

2 questions for everybody. 1) How can I order the years by their value,

  • 0

2 questions for everybody.

1) How can I order the years by their value, it crashes when I use DESC?

2) If I populate my list like so:

 string strConn = ConfigurationManager.ConnectionStrings["rde_410978ConnectionString"].ToString();
    SqlConnection con = new SqlConnection(strConn);
    SqlCommand cmd = new SqlCommand();
    cmd.Connection = con;
    cmd.CommandType = CommandType.Text;
    cmd.CommandText = "Select Distinct Year from MonthlySales DESC"; //DESC DOESNT WORK?

    DataSet objDs = new DataSet();
    SqlDataAdapter dAdapter = new SqlDataAdapter();
    dAdapter.SelectCommand = cmd;
    con.Open();
    dAdapter.Fill(objDs);
    con.Close();

    if (objDs.Tables[0].Rows.Count > 0)
    {
        ddItems.DataSource = objDs.Tables[0];
        ddItems.DataTextField = "Year";
        ddItems.DataValueField = "Year";
        ddItems.DataBind();
        ddItems.Items.Insert(0, "Select");
    }

How can I make the year selected appear under ddItems.SelectedItem?

WHERE Year = " + ddItems.SelectedItem + "GROUP BY Name ";

That part of another query doesn’t work when I populate my list dynamically, any reasons why/ how can I fix it.

Regards.

EDIT:
To make my second question clearer, after debugging its always selecting the top item in the drop down list not the actual selected item?

  • 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-03T11:56:21+00:00Added an answer on June 3, 2026 at 11:56 am

    First, in your sql you are missing “order by”…use this

    "Select Distinct Year from MonthlySales order by Year DESC"
    

    Second, you need to make use of the SelectedValue property to get your dropdown’s selected value…as below…

    WHERE Year = " + ddItems.SelectedValue + " GROUP BY Name";
    

    Having said that, I strongly recommend you to use…”parameterized” sql…Here is an example on how you could enable parameterized sql query…
    Give me parameterized SQL, or give me death

    Update:

    Looks like you are binding your dropdown on every post back…you may try this…

    if (!Page.IsPostBack && objDs.Tables[0].Rows.Count > 0)
        {
            ddItems.DataSource = objDs.Tables[0];
            ddItems.DataTextField = "Year";
            ddItems.DataValueField = "Year";
            ddItems.DataBind();
            ddItems.Items.Insert(0, "Select");
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Questions exactly like this have been asked before, i've read them all and tried
Other questions dealing with use of match_parent pre 2.2 have answers stating one should
Ha ii everybody,i have a question ,how can we implement the swiping gesture functionality
ciao everybody, I am becoming stupid about this question. I hope someone can help
Can someone show me to use xargs properly? Or if not xargs, what unix
Note: This question is posted here hello everybody, I have a predefind list of
Questions : I want to implement similar look and feel of the title bar
Questions about Python's subprocess.Popen() objects (Please assume a scenario where the number of bytes
Questions Are the posix macros S_ISREG, S_ISDIR etc linux only? I need to find
Questions (3 of them that are related) are bolded below. I'm trying to create

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.