Hi Everyone,
i got this Article from C-Sharpconer.com with the link https://www.c-sharpcorner.com/UploadFile/718fc8/databinding-with-combobox-in-ado-net/
- using System;
- 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.SqlClient;
-
- namespace DataBindingWIthComBox
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
-
- private void Form1_Load(object sender, EventArgs e)
- {
- SqlDataAdapter dadpter=new SqlDataAdapter("select * from student_detail","server=.;database=student;user=sa;password=wintellect");
- DataSet dset = new DataSet();
- dadpter.Fill(dset);
- comboBox2.DataSource = dset.Tables[0];
- comboBox2.DisplayMember = "rollno";
- comboBox2.ValueMember = "name";
- }
- private void comboBox2_SelectedIndexChanged(object sender,EventArgs e)
- {
- label2.Text = comboBox2.SelectedValue.ToString();
- }
- }
- }
i have few question with regrad to this, hope someone can help me.
Q1: in comboBox2.DataSource = dset.Tables[0]; what does Table[0] means
Q2: how do i display Two Column of data from Database in a combobox where if i select from combobox the other related data of that record should be populated to a textbox
Example:
i have a Table Name FileFolderPath with Id, Product, FolderPath. i need Id and Product to be shown in the combobox in Two columns and when i select a record from the combobox FolderPath has to be shown in the textbox or in a variable
Kindly someone please help me on this.