Click here to Skip to main content
15,910,981 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am having problem in saving selected item from combo box. , combo box is filled by database values.
my code is given below.I have made a method "viewincombo(string str)".
private void viewincombo(string str)
{
string connectionString = (@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Documents and Settings\nic-15\My Documents\ALRS.mdb");
OleDbConnection con = new OleDbConnection(connectionString);
con.Open();
//string str = "select thana from thana";
OleDbDataAdapter da = new OleDbDataAdapter(str, con);
DataSet ds = new DataSet();
da.Fill(ds);
comboBoxView.Visible = true;
comboBoxView.DataSource = ds.Tables[0];

}
and i am calling this method like this
private void buttonViewCombo_Click(object sender, EventArgs e)
{
string str = "select * from Licence_Category";
viewincombo(str);
comboBoxView.DisplayMember = "Licence_Category";
}
Table name is Licence_Category and field name is licence_category.
Above code is working but

textBoxField.Text = comboBoxView.SelectedItem.ToString();

doesnt not works.
Thanks in advance.
Posted

1 solution

you could also use
textBoxField.Text = comboBoxView.Text;
instead of
textBoxField.Text = comboBoxView.SelectedItem.ToString();
 
Share this answer
 
Comments
Member 10358986 18-Dec-13 6:30am    
Its working.
Thank you very much.
Member 14609275 23-Oct-19 11:38am    
hi there I'm a beginner to C#.what i want to ask is how can i save a data to SQL server table from a combobox

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