c# comboBox与数据库中的数据绑定

private void comBoxBinding()

        {

            SqlConnection connection = this.getConnection();

            connection.Open();

            SqlCommand command = new System.Data.SqlClient.SqlCommand();

            command = new SqlCommand("select State_Name_English,State_Name,StandSys,StandSys_English,StandSys_ID,State_ID from DbTable where StandSys_ID<>100 and isFinished='True' order by State_ID,StandSys_ID", connection);

            command.ExecuteNonQuery();

            SqlDataReader reader = command.ExecuteReader();

            if (reader.HasRows)

            {

                while (reader.Read())

                {

                    comboBox1.Items.Add(reader[2].ToString());

                }

            }

            comboBox1.SelectedText = "中国(GB)";

            reader.Close();

            connection.Close();

        }

 

你可能感兴趣的:(combobox)