Hirendra Sisodiya
posted
489 posts
since
Sep 01, 2009
from
|
|
Re: Access Data in listbox & combo box
|
|
|
|
|
|
|
|
|
|
|
apply this code:
private void Form1_Load(object sender, EventArgs e)
{
OleDbConnection thisConnection = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Put here database path with (extension .mdb)");
OleDbCommand cmd = new OleDbCommand();
string str = "select * from mytable";
cmd.CommandText = str;
thisConnection.Open();
OleDbDataAdapter mainTableAdapter = new OleDbDataAdapter(str, thisConnection);
DataSet thisDataSet = new DataSet();
try
{
mainTableAdapter.Fill(thisDataSet, "[Project Description]");
}
catch (Exception ex)
{
string error = ex.ToString();
}
thisConnection.Close();
comboBox1.DataSource = thisDataSet.Tables[0];
comboBox1.DisplayMember = "Name";
comboBox1.ValueMember = "Contact";
}
thanks
Please mark as answer if it helps
|
|
|
|
|
hirendra
BCA, MCA, M.Phil., MVP(Mindcraker)
|
|
|
|
|
|
Tanmay Sarkar
posted
194 posts
since
May 28, 2010
from
India
|
|
Re: Access Data in listbox & combo box
|
|
|
|
|
|
|
|
|
|
|
Thank you so much. but how i serialize them, consider 9834...... ,98444....,932222...., when i click 9 all 3 data will appear in list box, but when i change to 98 then only 2 two no will come..
Thanks for your code, it's good as well as help full. :-)
|
|
|
|
|
|
Tanmay Sarkar
posted
194 posts
since
May 28, 2010
from
India
|
|
Re: Access Data in listbox & combo box
|
|
|
|
|
|
|
|
|
|
|
I forget to use it:
string sqlquery = "select * from " + tablename + " order by " + displaycol + " asc";
Now it's OK!
|
|
|
|
|
|
Hirendra Sisodiya
posted
489 posts
since
Sep 01, 2009
from
|
|
Re: Access Data in listbox & combo box
|
|
|
|
|
|
|
|
|
|
|
|
|
|
hirendra
BCA, MCA, M.Phil., MVP(Mindcraker)
|
|
|
|
|
|