Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Satyapriya NayakRank #47 · 31.5K reputationPosted Jul 6, 2012, 12:06 AM EDT
Try this...
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.OleDb;
namespace Combobox
{
public partial class Form1 : Form
{
string ConnectionString = System.Configuration.ConfigurationSettings.AppSettings["dsn"];
OleDbCommand com;
//OleDbDataAdapter oda;
//DataSet ds;
string str;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
comboBox1.Items.Add("Choose employee");
OleDbConnection con = new OleDbConnection(ConnectionString);
con.Open();
str = "select * from employee";
com = new OleDbCommand(str, con);
OleDbDataReader reader = com.ExecuteReader();
while (reader.Read())
{
comboBox1.Items.Add(reader["name"]);
}
}
}
}
Thanks
If this post helps you mark it as answer
Kunal VaishyaRank #990 · 2K reputationPosted Jul 6, 2012, 12:03 AM EDT
{
string connectionString = "Data Source=.\\SQLEXPRESS;AttachDbFilename=C:\\Documents and Settings\\Administrateur\\Mes documents\\stockage.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";
cn.ConnectionString = connectionString;
cn.Open();
SqlDataAdapter d = new SqlDataAdapter("select nom_pdt from Produit", cn);
DataTable dt = new DataTable();
d.Fill(dt);
comboBox1.DataSource = dt;
//comboBox1.DataBindings.ToString();
}
Kunal VaishyaRank #990 · 2K reputationPosted Jul 6, 2012, 12:03 AM EDT
{
string connectionString = "Data Source=.\\SQLEXPRESS;AttachDbFilename=C:\\Documents and Settings\\Administrateur\\Mes documents\\stockage.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";
cn.ConnectionString = connectionString;
cn.Open();
SqlDataAdapter d = new SqlDataAdapter("select nom_pdt from Produit", cn);
DataTable dt = new DataTable();
d.Fill(dt);
comboBox1.DataSource = dt;
comboBox1.DisplayMember = "nom_pdt";
}
backiyalakshmi K38 reputationPosted Jul 6, 2012, 1:05 AM EDT