TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
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/
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"
;
// to display roll no. in combobox
comboBox2.ValueMember =
"name"
;
// to store name as value of combobox for selected roll no.
}
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.
Reply
Answers (
1
)
getting dropdown values for the calculation
Layout in other Layout