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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:04:43+00:00 2026-05-23T09:04:43+00:00

i you please help me out with my problem i am trying to create

  • 0

i you please help me out with my problem i am trying to create a function that output the data on a dropdownlist an setting my parameters my code goes as follow :

        public static List<string> GetTracks(out List<string> trackIds, string conferenceId)
    {

        var res = new List<string>();
        trackIds = new List<string>();
        var sqlCon = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
        SqlCommand cmd = new SqlCommand("select Track_name,Track_ID from TrackCommittee where Conference_id= @conferenceId", sqlCon);
        DataSet ds = new DataSet();
        cmd.Connection.Open();
        cmd.Parameters.Add(new SqlParameter("@conferenceId", conferenceId));



        using (SqlDataReader sdr = cmd.ExecuteReader())
        {
       while (sdr.Read())
       {
        res.Add(sdr.GetString(sdr.GetOrdinal("Track_name")));
        trackIds.Add(sdr.GetInt32(sdr.GetOrdinal("Track_ID")).ToString());
       }
               }


        cmd.Connection.Close();
        cmd.Dispose();
        return res;
    }

thanking you 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-05-23T09:04:43+00:00Added an answer on May 23, 2026 at 9:04 am

    Re-write the entire function like this:

    public static IEnumerable<ListItem> GetTracks(string conferenceId)
    {
        using (var sqlCon = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString))
        using (var cmd = new SqlCommand("select Track_name,Track_ID from TrackCommittee where Conference_id= @conferenceId", sqlCon))
        {
    
            cmd.Parameters.Add("@conferenceId", SqlDbType.Int).Value = conferenceId;
            sqlCon.Open();
    
            using (SqlDataReader sdr = cmd.ExecuteReader())
            {
                while (sdr.Read())
                {
                    yield return new ListItem(sdr[0].ToString(), sdr[1].ToString());
                }
            }
        }
    }
    

    And update your calling code like this:

    if (string.IsNullOrEmpty(os.SelectedValue)) 
    {
        os.Items.AddRange(GetTracks("all").ToArray());
    }
    

    And for better separation of presention and data tiers, I would modify GetTracks to return KeyValuePairs and the calling to add a select projection from KeyValuePair to ListItem.

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

Sidebar

Related Questions

Please help me out with an algorithm for the following problem - Given a
Can someone please help me out with a JavaScript/jQuery solution for this arithmetic problem:
Please help me out on this explode() function issue. I am getting unexpected results
I am trying to create a dynamic accordion. My problem is that I can
Please help me out here because im getting kind of confused.. I have a
Can someone please help me out with printing the contents of an IFrame via
Ok so could anyone please help me out with the VB for auto entering
I'm a developer and I suck at SQL:) Please help me out here. I'd
Could you please help me find out the time complexity of the Fleury' algorithm
Can someone please help me figure out a way to achieve the following (see

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.