Ifraz Imanudeen

Ifraz Imanudeen

  • NA
  • 60
  • 3.1k

DataBinding with Combobox

Sep 5 2018 5:59 AM
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/
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.ComponentModel;  
  4. using System.Data;  
  5. using System.Drawing;  
  6. using System.Linq;  
  7. using System.Text;  
  8. using System.Windows.Forms;  
  9. using System.Data.SqlClient;  
  10.   
  11. namespace DataBindingWIthComBox  
  12. {  
  13. public partial class Form1 : Form  
  14. {  
  15. public Form1()  
  16. {  
  17. InitializeComponent();  
  18. }  
  19.   
  20. private void Form1_Load(object sender, EventArgs e)  
  21. {  
  22. SqlDataAdapter dadpter=new SqlDataAdapter("select * from student_detail","server=.;database=student;user=sa;password=wintellect");  
  23. DataSet dset = new DataSet();  
  24. dadpter.Fill(dset);  
  25. comboBox2.DataSource = dset.Tables[0];  
  26. comboBox2.DisplayMember = "rollno"// to display roll no. in combobox  
  27. comboBox2.ValueMember = "name"// to store name as value of combobox for selected roll no.  
  28. }  
  29. private void comboBox2_SelectedIndexChanged(object sender,EventArgs e)  
  30. {  
  31. label2.Text = comboBox2.SelectedValue.ToString();  
  32. }  
  33. }  
  34. }  
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.

Answers (1)