Firstly, I think you should be clearing the ComboBox before adding
items to it. And secondly, I don't think the DropDown event is at all
appropriate for hitting the database to retrieve items. This should be
done at an earlier stage, probably form load.

On Apr 11, 12:37 pm, VIKAS GARG <[email protected]> wrote:
> hi;
>
> I am having a combobox in my for, I am getting all the data members into it
> using the database MYSQL. Everything is getting right. The data members are
> getting added to it
>
> private void comboBox1_DropDown(object sender, EventArgs e)
>   {
>
>   myCon = "DRIVER={MySql ODBC 5.1
> Driver};SERVER=127.0.0.1;PORT=3306;DATABASE=TEST;UID=root;PWD=vikas;OPTION=­3";
>   OdbcCon = new System.Data.Odbc.OdbcConnection(myCon);
>   OdbcCon.Open();
>   if (OdbcCon.State == ConnectionState.Open)
>   {
>   try
>   {
>
>   string str = "select Sender_id from sender_id where User_id = 58";
>   OdbcCom = new System.Data.Odbc.OdbcCommand(str, OdbcCon);
>   OdbcDr = OdbcCom.ExecuteReader();
>   while (OdbcDr.Read())
>   {
>   string xyz = (string)OdbcDr[0];
>   comboBox1.Items.Add(xyz);
>   }
>   }
>   catch (System.Data.Odbc.OdbcException ex)
>   {
> //This I have declared a read only textbox to see whatever response i am
> getting after any line of code
>
>   LogText.AppendText("\r\n" + ex.Message);
>
>   }
>   }
>   else
>   {
>   LogText.AppendText("\r\n The connection could not be opened");
>   }
>
>   }
>
> But this is getting me a problem, that is whenevr I click on the drop down
> Icon, the combobox is flooded with a copy of
>
> itself. Because I have added this to dropDown event of ComboBox. please
> guide me what change should i make there.
>
> I am using tagPage in my form.

Reply via email to