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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T13:50:27+00:00 2026-05-20T13:50:27+00:00

populating the combox and displaying the value in the combobox for eg. if I

  • 0

populating the combox and displaying the value in the combobox
for eg. if I choose name in the combobox the corresponding ID should display in the text box . Do anybody know? I am learning c#. I tried it can anybody examine the following code.using System;

I wanted to create a array of store the value and then write it out in the text box. can anybody help

using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace DBExample
{
    public partial class Form1 : Form
    {
        private OleDbConnection dbConn; // Connectionn object
        private OleDbCommand dbCmd; // Command object
        private OleDbDataReader dbReader;// Data Reader object
        private Member aMember;
        private string sConnection;
        // private TextBox tb1;
        // private TextBox tb2;
        private string sql;
        public Form1()
        {
            InitializeComponent();
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            try
            {
                // Construct an object of the OleDbConnection 
                // class to store the connection string 
                // representing the type of data provider 
                // (database) and the source (actual db)
                sConnection =
                        "Provider=Microsoft.Jet.OLEDB.4.0;" +
                        "Data Source=c:member.mdb";
                dbConn = new OleDbConnection(sConnection);
                dbConn.Open();
                // Construct an object of the OleDbCommand 
                // class to hold the SQL query. Tie the 
                // OleDbCommand object to the OleDbConnection
                // object
                sql = "Select * From memberTable Order " +
                        "By LastName , FirstName ";
                dbCmd = new OleDbCommand();
                dbCmd.CommandText = sql;
                dbCmd.Connection = dbConn;
                // Create a dbReader object 
                dbReader = dbCmd.ExecuteReader();
                while (dbReader.Read())
                {
                    aMember = new Member
                                (dbReader["FirstName"].ToString(),
                                 dbReader["LastName"].ToString(),
                                 dbReader["StudentId"].ToString(),
                                 dbReader["PhoneNumber"].ToString());
                    // tb1.Text = dbReader["FirstName"].ToString();
                    // tb2.Text = dbReader["LastName"].ToString();
                    // tb1.Text = aMember.X().ToString();
                    //tb2.Text = aMember.Y(aMember.ID).ToString(); 
                    BindingList<Member> comboBoxList = new BindingList<Member>();

                    comboBox1.DataSource = comboBoxList; 
                    comboBox1.DisplayMember = "FirstName"; 
                    comboBox1.ValueMember = "ID";
                    // this.comboBox1.Items.Add("aMember.FirstName.ToString()");
                    // this.listBox1.Items.Add(aMember.ToString());
                    // MessageBox.Show(aMember.ToString());
                    // Console.WriteLine(aMember.ToString());
                }
                dbReader.Close();
                dbConn.Close();
            }
            catch (System.Exception exc)
            {
                MessageBox.Show("show" + exc);
            }
        }
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            textBox2.Text = comboBox1.SelectedValue.ToString();
            this.textBox1.Text = comboBox1.SelectedItem.ToString();
        }


        private void DbGUI_Load(object sender, EventArgs e)
        {
        }



        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }
        private void textBox1_TextChanged(object sender, EventArgs e)
        {
        }
    }

}
  • 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-20T13:50:28+00:00Added an answer on May 20, 2026 at 1:50 pm

    you should try something like this

    BindingList<Member> comboBoxList = new BindingList<Member>();
    while (dbReader.Read())
    {
        aMember = new Member
                    (dbReader["FirstName"].ToString(),
                     dbReader["LastName"].ToString(),
                     dbReader["StudentId"].ToString(),
                     dbReader["PhoneNumber"].ToString());
        // tb1.Text = dbReader["FirstName"].ToString();
        // tb2.Text = dbReader["LastName"].ToString();
        // tb1.Text = aMember.X().ToString();
        //tb2.Text = aMember.Y(aMember.ID).ToString(); 
    
        comboList.Add(aMember)
    
    }
    
    comboBox1.DataSource = comboBoxList; 
                            comboBox1.DisplayMember = "FirstName"; 
                            comboBox1.ValueMember = "ID";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

im populating the data in the combo box using dataset tables...with some table name..now
I am populating a combobox dropdown with node fields from an Xml document. I
I'm working on populating a combobox in visual studio 2005 using vb and I'm
I'm dynamically populating a select box with option values based on search results returned
I have a combo box. The values are populating in combo box from DB.
I am populating combo box from database. In debug i can see that the
I am populating a Dojo Combobox dropdown with values from JSON. The code below
I have been populating my Items to a combox using the designer and all
How to speed up a combo box populating speed? Academically speaking, imagine that a
I'm populating an Excel sheet from DTS. The result is formatted as text since

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.