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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:00:18+00:00 2026-06-17T09:00:18+00:00

I am attempting load employee data from a stored procedure into a listbox in

  • 0

I am attempting load employee data from a stored procedure into a listbox in a form load event by ID and assign each with an image. The code above is what I have thus far. So what I’m trying to do here is to fill the listview with data from my data reader.

SqlConnection conn = new SqlConnection(
                            @"Data Source=MyPC\Test;Initial Catalog=TEST5;Integrated Security=True");
SqlCommand cmd = new SqlCommand("SELECT emp_first_name FROM Employees", conn);
cmd.CommandType = CommandType.Text;

SqlDataReader dr = cmd.ExecuteReader();

listView1.Items.Clear();

while (dr.Read())
{
    ListViewItem recs = new ListViewItem();

    recs.Text = dr["dept_name"].ToString();
    recs.Text = dr["emp_first_name"].ToString();
    recs.Text = dr["emp_last_name"].ToString();
    recs.Text = dr["emp_email"].ToString();
    recs.Text = dr["emp_phone"].ToString();
    recs.Text = dr["emp_position"].ToString();
    recs.Text = dr["emp_address1"].ToString();
    recs.Text = dr["emp_address2"].ToString();
    recs.Text = dr["emp_city"].ToString();
    recs.Text = dr["emp_state"].ToString();
    recs.Text = dr["emp_postal_code"].ToString();

    recs.Tag = dr["empId"].ToString();
    recs.ImageIndex = 0;
    listView1.Items.Add(recs);
}

Thank you in advance.

  • 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-17T09:00:19+00:00Added an answer on June 17, 2026 at 9:00 am

    Your query is currently only returning one fieid:

    SqlCommand cmd = new SqlCommand("SELECT emp_first_name FROM Employees", conn);
    

    I’m guessing you wanted this:

    SqlCommand cmd = new SqlCommand("SELECT * FROM Employees", conn);
    

    You need to open the connection and close your disposable resources. Your current code is constantly replacing the recs.Text property to the point that the only thing you should see in the list are “emp_postal_code” values. I suspect you are looking for something like this, where you display the user name as the main item of the ListViewItem and then include the other information as SubItems of the item (for when displaying in Detailed view):

    listView1.Items.Clear();
    
    using (SqlConnection conn = new SqlConnection(...)) {
      conn.Open();
      using (SqlCommand cmd = new SqlCommand("SELECT * FROM Employees", conn)) {
        using (SqlDataReader dr = cmd.ExecuteReader()) {
          while (dr.Read()) {
            ListViewItem recs = new ListViewItem();
    
            recs.Text = dr["emp_first_name"].ToString() + " " +
                        dr["emp_last_name"].ToString();
    
            recs.SubItems.Add(dr["dept_name"].ToString());
            recs.SubItems.Add(dr["emp_email"].ToString());
            etc...
    
            recs.Tag = dr["empId"].ToString();
            recs.ImageIndex = 0;
            listView1.Items.Add(recs);
          }
        }
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm attempting to load data from an undocumented API (OsiriX). Getting the NSManagedObject like
I am attempting to load from text files, queries into an MS Access Queries
I am attempting to load data from a *.csv file off my VM of
I'm attempting to load a bitmap image from an images folder from within the
I'm attempting to load a scene from a file into Three.js (custom format, not
I'm attempting to load numerical data from CSV files in order to loop through
I am attempting to load some json data into a custom JQuery function. There
I am attempting to load user data into an Ubuntu 12.04 LTS AMI (ami-a29943cb,
I am attempting to load JSON content into a listview containing image and text
I'm attempting to load JSON (from php's json_encode) into a Backbone JS collection. I've

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.