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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:19:29+00:00 2026-05-23T12:19:29+00:00

I am retrieving 4 Fields from my database table. Now i want to add

  • 0

I am retrieving 4 Fields from my database table. Now i want to add them to a dynamic list <>. How to add those into the list.
I tried this :

public class myclass
{
   public string StdDetails, StdAdderID;
   public DateTime StdAddedDate, StdAddedTime;
}

public void buttonClick()
{
    List<myclass> StdList = new List<myclass>();

    myclass mc = new myclass();

    OdbcCommand readStd = 
        new OdbcCommand("SELECT StdDetails, StdAddedDate," +
                        "StdAddedTime, StdAdderID" +
                        "FROM Students", Conn);

    OdbcDataReader readStdreader = 
        readStd.ExecuteReader(CommandBehavior.SingleRow);

    while (readStdreader .Read())
    {
        mc.StdDetails = readStdreader.GetString(0);
        mc.StdDetails = readStdreader.GetString(3); 
        mc.StdDetails = readStdreader.GetDate(1);
        mc.StdDetails = readStdreader.GetDateTime(2);
        StdList.Add(mc);
    }
    MessageBox.Show(StdList[0].ToString());
}

In the message box the value isn’t displayed? what to do.please help

//SORRY FOR THE TYPOS :

replace these 3 lines :

mc.StdDetails = readStdreader.GetString(3); 
        mc.StdDetails = readStdreader.GetDate(1);
        mc.StdDetails = readStdreader.GetDateTime(2);

with :

mc.StdAddedDate= readStdreader.GetString(3); 
                mc.StdAdderID= readStdreader.GetDate(1);
                mc.StdAddedTime= readStdreader.GetDateTime(2);
  • 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-23T12:19:29+00:00Added an answer on May 23, 2026 at 12:19 pm

    You’re only creating a single instance of myclass, so your list will be full of references to the same object. You want this instead:

    while (readStdreader.Read())
    {
        myclass mc = new myclass();
        mc.StdDetails = readStdreader.GetString(0);
        mc.StdAdderID = readStdreader.GetString(3);
        mc.StdAddedDate= readStdreader.GetDate(1);
        mc.StdAddedTime = readStdreader.GetDateTime(2);
        StdList.Add(mc);
    }
    

    Note how I’ve changed the properties that are assigned, too – the code you posted attempts to assign to StdDetails repeatedly.

    You also haven’t overridden ToString in myclass, so calling ToString() isn’t going to give you anything particularly useful.

    Additionally:

    • You should look into the .NET naming conventions; your naming is all over the shop at the moment. (What does std mean here? You’ve used it for almost everything…)
    • Public fields are a really bad idea; use properties instead
    • Use using statements to close readers, commands, connections etc in a reliable way.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am retriving data from database.TableName:Contacts. There are two fields of this table.First_Name and
I am retrieving 3 fields from a database, and by default, only the username
When retrieving a lookup code value from a table, some folks do this... Dim
Right now I'm retrieving data from my database as follows: SELECT id, UNIX_TIMESTAMP(cdate) as
Im having problems retrieving a field from my ms-access database. The table name is
We have a flash retrieving information from an XML file. Right now we are
I'm retrieving a float value from a mysql database on a php page (2.5,
I am retrieving data from an Oracle database and binding the same to a
retrieving items from table that fall between a date range. the date (db table
I have user table having fields gender and first name like this.. The value

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.