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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:22:24+00:00 2026-06-08T21:22:24+00:00

I have legacy code that I am slowly moving to C# MVC. How would

  • 0

I have legacy code that I am slowly moving to C# MVC. How would I create a dropdownlist from a data table or dataset? I do not want to create properties and loop through a list because I have too many ancient MS Access queries to deal with.

CONTROLLER:

 using (SqlConnection Connection = new SqlConnection(ConnectionString))
        {
            string commandstring = "select column1 from table1";
            SqlCommand command = new SqlCommand(commandstring, Connection);
            Connection.Open();
            SqlDataAdapter da = new SqlDataAdapter();
            DataSet ds = new DataSet();
            da.SelectCommand = command;
            da.Fill(ds, "data1");
            Connection.Close();
        }
  • 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-08T21:22:25+00:00Added an answer on June 8, 2026 at 9:22 pm

    As George stated, I would suggest moving the domain logic into a data access layer and using entities to hold your objects that were returned from a query. You can use Dapper which allows you to use raw SQL queries and have the results mapped to models. Its performance is same as SqlDataReader. Here is an extension method that will take a list of models and turn them into a dropdown list.

    public static IEnumerable<SelectListItem> ToSelectList<T, TTextProperty, TValueProperty>(this IEnumerable<T> instance, Func<T, TTextProperty> text, Func<T, TValueProperty> value, Func<T, bool> selectedItem = null)
    {
        return instance.Select(t => new SelectListItem
        {
            Text = Convert.ToString(text(t)),
            Value = Convert.ToString(value(t)),
            Selected = selectedItem != null ? selectedItem(t) : false
        });
    }
    

    Then you can use the code like …

    var list = SomeQuery();
    list.ToSelectList(x => x.Name, x => x.id, x => x.id == selectedId);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Scenario: old legacy code in rpg have to consume data from a new web
I have the following function from some legacy code that I am maintaining. long
I have the following legacy code that I'd like to remove eval from: eval('view
I have the following legacy code that I would like to mimic, with all
I have some legacy code that compiles with both -02 and -03 set. From
I have some legacy python code that using pypar and mpich2 to transmit data
I have some legacy code that uses shmget/shmat/shmdt to create, attach and manage shared
I have existing legacy code that is using a standard form. I would like
We have an ASP.NET MVC 4 application that links to legacy native code. The
I have some legacy code that was used to monitor my applications cpu,memory etc

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.