Click here to Skip to main content
15,893,814 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
how to bind drop down list from Sql Server 2008 in c# in windows application
Posted
Updated 29-Jan-15 19:55pm
v2
Comments
Leo Chapiro 30-Jan-15 1:55am    
What have you tried, dude?
Khan Sameer 30-Jan-15 2:01am    
i want value display from the table in a drop down list

1 solution

Refer below links or Code hope these help.....
Writing the code in Form1.cs
C#
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 BindComboBox 
{ 
public partial class Form1 : Form 
{ 
public Form1() 
{ 
InitializeComponent(); 
} 
private void Form1_Load(object sender, EventArgs e)
 { 
loadCountry();
 } 
public void loadCountry() 
{ 
DataTable dt = new DataTable(); 
try 
{ 
using (SqlConnection con = new SqlConnection("Data Source = testdb;Initial Catalog = ABC;Uid = sa;Password = PassWord123;")) 
{ 
using (SqlDataAdapter adp = new SqlDataAdapter("SELECT * FROM country", con)) 
{
 adp.Fill(dt); 
comboBox1.DisplayMember = "Country"; 
comboBox1.ValueMember = "Id"; 
comboBox1.DataSource = dt; 
} 
} 
} 
catch (Exception ex) 
{ 
throw ex; 
} 
} 
} 
} 

http://www.dotnetsharepoint.com/2013/08/how-to-bind-data-in-combobox-from.html[^]


http://csharp.net-informations.com/dataset/dataset-combobox.htm[^]
http://www.aspdotnet-suresh.com/2012/10/showbind-data-to-aspnet-dropdownlist.html[^]

Happy Coding...
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900