View Single Post
Join Date: Mar 2008
Posts: 136
Reputation: cVz is an unknown quantity at this point 
Solved Threads: 7
cVz's Avatar
cVz cVz is offline Offline
Junior Poster

Re: How to refresh Combobox items

 
0
  #4
Jan 6th, 2009
Yo dude, you can always just refresh the connection, you don't need to close your form,

i take it you want something like this

  1. using System.Data.SqlClient;
  2.  
  3.  
  4. namespace TestDummyTWO
  5. {
  6. public partial class Form1 : Form
  7. {
  8. SqlConnection sqlcon =
  9. new SqlConnection("Data Source=.;Initial Catalog=your_table;Integrated Security=True;Asynchronous Processing = True");
  10.  
  11. SqlCommand sqlCom = new SqlCommand("SELECT ITEMS FROM YOUR_TABLENAME");
  12.  
  13. public Form1()
  14. {
  15. InitializeComponent();
  16. }
  17.  
  18. private void Form1_Load(object sender, EventArgs e)
  19. {
  20. SqlDataReader reader = sqlCom .ExecuteReader();
  21.  
  22. // Looping throuhg the list of data
  23. while (reader.Read())
  24. {
  25. // Fill combo Box with data
  26. comboBox1.Items.Add(reader["ITEMS"]);
  27. }
  28. }
  29.  
  30. private void button1_Click(object sender, EventArgs e)
  31. {
  32. // you added the new item from the tex box into the DATA TABLE
  33. // Not the combobox
  34. // use sqlCom again to do so
  35.  
  36. sqlCom.CommandText = "Insert into blah blah";
  37.  
  38. /* THIS IS WHAT YOU HAVE TO DO */
  39. sqlcon.Close();
  40. sqlcon.Open();
  41. }

Hope that helps ...
Last edited by cVz; Jan 6th, 2009 at 4:11 am.
Delphi & C# programmer deluxe...
Reply With Quote