hi ,
i m new to c#;
In my desktop application i want to show combobox as follows:
1-abc
2-def
3-ghi
etc.
my database table structure is :
id description
1 abc
2 def
3 ghi
In short i want something like
combo1.displaymember="id-description";
and
combo1.valuemember="id";
please suggest me possible workaround for this
VulpesPosted May 5, 2011, 6:46 AM
Sam HobbsPosted May 5, 2011, 11:44 PM
Ankit NandekarPosted May 5, 2011, 7:58 AM
Ankit NandekarPosted May 5, 2011, 2:31 AM
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication8
{
public partial class Form3 : Form
{
public Form3()
{
InitializeComponent();
}
private void Form3_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data Source=C3;Initial Catalog=Student;Persist Security Info=True;User ID=sa;Password=p@ssw0rd");
SqlDataAdapter da = new SqlDataAdapter("select id , id-description from description", con);
DataSet ds = new DataSet();
da.Fill(ds);
comboBox1.DataSource = ds.Tables[0].DefaultView;
comboBox1.DisplayMember = "id-description";//id-description name which u want to show in Combobox
comboBox1.ValueMember = "id ";
}
}
}