Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
I have a combo box with data bounded from a Data Base. I am having problems when adding new items to database and also editing and deleting items. When I do those actions, The combobox is not getting updated until the app restart. I am just a student and I need help for this. I bounded the data through the option available in Visual Studio 2010.
Posted
Updated 11-Sep-13 4:18am
v2
Comments
norbitrial 11-Sep-13 10:12am    
Add the code for your question.
Sergey Alexandrovich Kryukov 11-Sep-13 10:18am    
Sorry, this is not a question. And now: any effort?

Your "just a student" is absurd. The student is the one who study, not an excuse.

—SA
BulletVictim 11-Sep-13 10:20am    
Most simplistic way I know of is: After you have added data to the database clear the items in the combobox and then run the bind again.
But as norbitrial said. We will need to see the code that is related to your problem.
Kaveen Abeywansa 11-Sep-13 10:23am    
I am using the option available which will bind the data. I have coded for it. I used the arrow on the combobox to do so.
BulletVictim 11-Sep-13 10:27am    
Honestly some advise since you are still a student, try to refrain from using the GUI option in data control as much as possible

It can be a good solution if you put into your form a refresh button and with it you can make a query for your database and rebind the data to your combobox.
 
Share this answer
 
Comments
Member 10986425 29-Sep-15 4:15am    
This is not proper way to solve problem it needs to be automatic no any inputs
Just googled for 2 seconds and found this:
C#
foreach (Control ctl in this.Controls)
{
    ctl.ResetBindings();
}
 
Share this answer
 
Thanks for all who spent their time to help. Even I didn't get the answer, I found the way to do so. I will post it as a help to another beginner like me.

SqlConnection con = new SqlConnection(@"PATH");
con.Open();
SqlCommand cmd = new SqlCommand("select Field from TableName", con);
SqlDataAdapter SDA = new SqlDataAdapter();
SDA.SelectCommand = cmd;
DataTable DT = new DataTable();
SDA.Fill(DT);
comboBox1.DataSource = DT;
con.Close();
 
Share this answer
 

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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