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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:25:44+00:00 2026-06-09T18:25:44+00:00

I am retrieving whole data from database in list?Now i have four class like:

  • 0

I am retrieving whole data from database in list?Now i have four class like:

Student class:

public class StudentTable
{
    public string StudentID { get; set; }
    public string StudentName { get; set; }

    public StudentTable()
    {
    }

    public StudentTable(string aStudentID, string aStudentName)
    {
        StudentID = aStudentID;
        StudentName = aStudentName;
    }
}

Course class

public class CourseTable
{
    public string CourseID { get; set; }
    public string CourseName { get; set; }
    public int Credits { get; set; }

    public CourseTable()
    {
    }

    public CourseTable(string aCourseID, string aCourseName, int aCredits)
    {
        CourseID = aCourseID;
        CourseName = aCourseName;
        Credits = aCredits;
    }
}

Enrollment class

public class Enrollment
{
    public StudentTable StudentData { get; set; }
    public CourseTable CourseData { get; set; }
    public DateTime DOE { get; set; }

    public Enrollment()
    {
    }

    public Enrollment(StudentTable aStudentData, CourseTable aCourseData, DateTime aDOE)
    {
        StudentData = aStudentData;
        CourseData = aCourseData;
        DOE = aDOE;
    }
}

StudentScore class:

public class StudentScore
{

    public Enrollment EnrollmentData { get; set; }
    public int Score { get; set; }

    public StudentScore()
    {
    }

    public StudentScore(Enrollment aEnrollmentData, int aScore)
    {
        EnrollmentData = aEnrollmentData;
        Score = aScore;
    }
}

and i retrieve the data from database through query now i want to display the StudentID from list but in the StudentScore Class i have EnorllmentData not StudentID.

try
{
    var aStudentScore = EnrollmentDB.GetAllScore();
    comboBox3.DataSource = aStudentScore;

    comboBox3.DisplayMember = "StudentID";
    comboBox3.ValueMember = "CourseID";
    //comboBox3.ValueMember = "Score";
}
catch (Exception ex)
{
    MessageBox.Show(ex.Message, ex.GetType().ToString());
}

It show me a DisplayMember error can you please help me to fix it, becaouse in StudentScore class have no StudentID variable so How can i display the StudentID from StudentScore Class?

  • 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-09T18:25:45+00:00Added an answer on June 9, 2026 at 6:25 pm

    So, first you had the Cannot bind to new display member error which Jon solved by showing you how to use dot-notation.

    After that you are now getting the Unable to cast error. Without seeing that GetAllScore method I can’t say exactly why. However, you can do the heavy lifting yourself in code, and make the binding simple, by adding read-only properties to StudentScore to return what you want to use as the Display and Value Members. (I have to say that using StudentID as a DisplayMember and CourseID as a ValueMember doesn’t make any sense to me.)

    Add something like this to your StudentScore:

    public String UseAsDisplayMember
    {
        get 
        {
            return EnrollmentData.StudentData.StudentID; 
        }
    }
    public string UseAsValueMember
    {
        get 
        {
            return EnrollmentData.CourseData.CourseID; 
        }
    }
    

    Then set the data binding as:

    comboBox3.DisplayMember = "UseAsDisplayMember";
    comboBox3.ValueMember = "UseAsValueMember";
    

    This should get you working, but it feels more like a band-aid than a real fix.

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

Sidebar

Related Questions

I have a problem with retrieving data from a database using PHP statements. At
I'm working on an application that opens a database connection and retrieving data from
In my java code,I am retrieving some multibyte data from database and making some
I have a query on retrieving data sent as JSON from a JavaScript, inside
* I have saved some data from spinner in to the database. But I
For some reason I'm having a problem retrieving data from my database. It leaves
I am testing a database storage after retrieving data from the internet, I would
I am retrieving data from database using AJAX and PHP. In database one of
I'm retrieving data from a MySQL table and displaying it on a webpage using
I am retrieving an array values from database which save multi dimensional array..i want

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.