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

  • Home
  • SEARCH
  • 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 7847845
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T18:01:17+00:00 2026-06-02T18:01:17+00:00

I am using ObjectDataSource for my Gridview. The function I am using to return

  • 0

I am using ObjectDataSource for my Gridview.
The function I am using to return values is just returning a single value that is the last one from the table.
What changes do I make to return all the values.

public class Employees
    {
        public int e_number;
        public string e_name;
        public string e_designation;
        private SqlConnection conn = null;
        private SqlCommand cmd = null;
        private string constring = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;


        public Employees()
        {
            conn = new SqlConnection(constring);
            cmd = new SqlCommand();
        }
        public int Employee
        {
            get
            {
                return e_number;
            }
            set
            {
                e_number = value;
            }
        }

        public  string Name
        {
            get
            {
                return e_name;
            }
            set
            {
                e_name = value;
            }
        }
        public string Designation
        {
            get
            {
                return e_designation;
            }
            set
            {
                e_designation = value;
            }
        }   


        public Employees GetEmployee()
        {
            string strquery = "select [Number],[Name],[Designation] from [Users]";
            conn.Open();
            cmd.Connection = conn;
            cmd.CommandText = strquery;
             SqlDataReader objSqlDataReader = cmd.ExecuteReader();
            int counter = 0;
           // ArrayList myObj = new ArrayList();
          //  Employees objEmployees = new Employees();
            Employees emp = null;

            //if (objSqlDataReader.Read())
            while(objSqlDataReader.Read())
            {
               emp = new Employees();
               // myObj[counter] = new Employees();
              //  Employees employee = new Employees();
                emp.Employee = (int)objSqlDataReader["Number"];
                emp.Name=(string)objSqlDataReader["Name"];
                emp.Designation = (string)objSqlDataReader["Designation"];



               // objEmployees.e_number = (int)objSqlDataReader["Number"];
               // objEmployees.e_name = (string)objSqlDataReader["Name"];
                //objEmployees.e_designation = (string)objSqlDataReader["Designation"];


            }

            conn.Close();
            return emp; 




            //return objEmployees;



        }
    }
}

I have tried all approaches like making array of objects but I am not able to .
Please could you tell me what to add in my code.

  • 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-02T18:01:19+00:00Added an answer on June 2, 2026 at 6:01 pm

    You need to return a list of employees. You are only returning a single one, the last instance after you exit the loop:

    public List<Employees> GetEmployees()
    {
        ..
        List<Employees> emps = new List<Employees>();
        Employees emp = null;
    
        while (..)
        {
            emp = new Employees();
            ..
            emps.Add(emp);
        }
    
        return emps;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Background I have a GridView that builds a table using an ObjectDataSource . This
I'm using an ObjectDataSource to bind an object to a GridView. In the OnRowDataBound
I have a Gridview that displays paged results from a search query. The problem
I have a telerik radgrid that is doing an insert using an objectdatasource. The
I using an ObjectDataSource (Should receive 5 rows) and a gridview. When I open
I'm trying to sort a gridview with my objectdatasource which uses a function import
Quick overview Trying to insert a Business Object using ObjectDataSource (on a GridView) Get
I'm creating a gridview using an objectdatasource and it works fine when pulling all
I've got a Page , a GridView using an ObjectDataSource with a SelectMethod and
I've a Gridview control using an ODS(ObjectDataSource) to fetch data. For the best performance

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.