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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T06:16:21+00:00 2026-06-16T06:16:21+00:00

I want to create a sorted list of users that appear in one datatable

  • 0

I want to create a sorted list of users that appear in one datatable “StatsTable”.

I need to get the userID from StatsTable and then use this to find the UserName in another datatable “UserTable”. When I have these I want to make the userID the Key and the UserName the Value in the sorted list.

I managed to get the userID and add it to the sorted list but the userName is coming through as “System.Data.EnumerableRowCollection`1[System.String]”.

What am I doing wrong? Thanks for your help.

    SortedList UserList = new SortedList();

    List<double> listofUserIDs = StatsTable.AsEnumerable()
    .Select(uid => uid.Field<double>("UserID")).ToList<double>();
    foreach (double UID in listofUserIDs)
    {
        string userName = UserTable.AsEnumerable()
            .Where(id => double.Equals(id.Field<double>("UserID"), UID))
        .Select(name => name.Field<string>("First_Name") + " " + name.Field<string>("Last_Name")).ToString();

         UserList[UID] = userName;
    }
  • 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-16T06:16:22+00:00Added an answer on June 16, 2026 at 6:16 am

    You should use Enumerable.Join to link both tables and select what you need. In this case i would use a Tuple<int, string> whereas the int is the UserID(a UserID with decimal places makes no sense, does it?) and the string is the username:

    var query = from rStats in StatsTable.AsEnumerable()
                join rUser in UserTable.AsEnumerable()
                on rStats.Field<int>("UserID") equals rUser.Field<int>("UserID")
                select new {
                    UserID   = rStats.Field<int>("UserID"), 
                    UserName = string.Format("{0} {1}"
                                   , rUser.Field<string>("First_Name")
                                   , rUser.Field<string>("Last_Name"))
                };
    
    List<Tuple<int, string>> users = query
        .OrderBy(u => u.UserName)
        .Select(u => Tuple.Create(u.UserID, u.UserName))
        .ToList();
    

    You can access a tuple via the Item properties:

    foreach(var user in users)
        Console.WriteLine("UserID:{0} UserName:{1}",user.Item1,user.Item2);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i want create a custom json data from the mssql 2008 results so that
I want to implement simple SQL query that will return a sorted list. The
I have sorted list of datetime.time and want to create intervals like. If I
I want to be able to create a program that will take a list
i want create multiple search where statement $where_search is a multiple condition from post
I want create wordpress website into which I want create user management... That means
I want create module which update list of usb devices automatically (not only mass
I want to create a new field (or two) in my table that is
I want to create a Silverlight app to extract and manipulate data from an
I'm using jQuery UI's sortable and I want the by the user sorted list

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.