Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > Duplicate items on toolstripComboBox
 

Duplicate items on toolstripComboBox

Higuys,

I have a toolstripcombobox that i want to populate data to froma sql table. I have got this to work however the problem i have is the information is duplicated and does not stop displaying, it just keeps going and going. Here is the code i have used.

privatevoidtimer1_Tick(objectsender,EventArgse)
{
toolStripComboBox1.Text="";
stringconnectionString="DataSource=sql.support.co.uk;InitialCatalog=support;PersistSecurityInfo=True;UserID=support;Password=";
stringqueryString="SELECTagentFROMGSStatus";
using(SqlConnectionconnection=newSqlConnection(connectionString))
{
SqlCommandcommand=newSqlCommand(queryString,connection);
connection.Open();
SqlDataReaderreader=command.ExecuteReader();
while(reader.Read())
{
intcount=reader.FieldCount;
for(inti=0;i<count;i++)
toolStripComboBox1.Text+=System.Convert.ToString(reader[i])+"";
toolStripComboBox1.Text+="\n";
}
reader.Close();
}
}

Any ideas?

Thanks
Needmoreberformewallaby  Wednesday, February 11, 2009 9:15 AM
Have worked it. Any else having this problem, Here is the code below

toolStripComboBox1.Items.Clear();
stringconnectionString="DataSource=sql.support.co.uk;InitialCatalog=support;PersistSecurityInfo=True;UserID=support;Password=";
stringqueryString="SELECTagentFROMGSStatus";
using(SqlConnectionconnection=newSqlConnection(connectionString))
{
SqlCommandcommand=newSqlCommand(queryString,connection);
connection.Open();
SqlDataReaderreader=command.ExecuteReader();
while(reader.Read())
{
intcount=reader.FieldCount;
for(inti=0;i<count;i++)
toolStripComboBox1.Items.Add(System.Convert.ToString(reader[i]));
//toolStripComboBox1.Items.Add("\n");
}
reader.Close();
}
Needmoreberformewallaby  Wednesday, February 11, 2009 11:54 AM
Have worked it. Any else having this problem, Here is the code below

toolStripComboBox1.Items.Clear();
stringconnectionString="DataSource=sql.support.co.uk;InitialCatalog=support;PersistSecurityInfo=True;UserID=support;Password=";
stringqueryString="SELECTagentFROMGSStatus";
using(SqlConnectionconnection=newSqlConnection(connectionString))
{
SqlCommandcommand=newSqlCommand(queryString,connection);
connection.Open();
SqlDataReaderreader=command.ExecuteReader();
while(reader.Read())
{
intcount=reader.FieldCount;
for(inti=0;i<count;i++)
toolStripComboBox1.Items.Add(System.Convert.ToString(reader[i]));
//toolStripComboBox1.Items.Add("\n");
}
reader.Close();
}
Needmoreberformewallaby  Wednesday, February 11, 2009 11:54 AM

You can use google to search for other answers

Custom Search

More Threads

• ubound and unbound cols
• Selecting a record from a Datagrid
• Number the rows in the Datagrid
• How to add a multiline textbox column to a datagridview programmatically?
• Find
• Export window form to doc file c# windows application
• checkbox clicked event in datagrid
• how can we pass the combobox value to the other form
• Directory Polling with Windows Service
• autoincrement field and binding