Click here to Skip to main content
15,886,258 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
using (SqlCommand cmd = new SqlCommand())
                   {


                       cmd.CommandText = "Select Distinct Supplier From Material Where Material='" + comboBoxEdit2.Text + "'; ";
                       cmd.Connection = sqlconn;
                       sqlconn.Open();



                       using (SqlDataReader reader = cmd.ExecuteReader())
                       {

                           while (reader.Read())
                           {

                               this.comboBoxEdit3.Properties.Items.Add((string)reader[0]);

                           }

                       }

                       sqlconn.Close();

                   }


What I have tried:

Hello, when the comboboxedit2 in russian chachter, comboboxedit3 cant get the values from database, but when the comboboxedit2 in english chachter, comboboxedit3 show the values so i need a help...
Posted
Updated 28-Feb-16 21:43pm

1 solution

Try using the parameter instead, like this:
C#
using (SqlCommand cmd = new SqlCommand())
{


  cmd.CommandText = "Select Distinct Supplier From Material Where Material=@material;";
  cmd.Parameters.AddWithValue("@material", comboBoxEdit2.Text);
  cmd.Connection = sqlconn;
  sqlconn.Open();

  using (SqlDataReader reader = cmd.ExecuteReader())
  {
    while (reader.Read())
    {
      this.comboBoxEdit3.Properties.Items.Add((string)reader[0]);
    }
  }
  sqlconn.Close();
}
 
Share this answer
 
Comments
Member 10409000 29-Feb-16 3:51am    
Thank you, it works :)
Paw Jershauge 29-Feb-16 3:55am    
Your welcome ;) ;) ;)

And remember, ALWAYS use parameter
Member 10409000 29-Feb-16 5:09am    
thanks again, i will remember :)

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