publicForm1() {
InitializeComponent();
}
SqlConnection Con = new SqlConnection("Your Connection String");
private void FillCombo_AnimalType()
{
SqlDataAdapter da = new SqlDataAdapter("Select animalcode, animalkind From animaltype", Con);
DataTable dt = new DataTable();
da.Fill(dt);
comboBox1.DataSource = dt;
comboBox1.DisplayMember = "animalkind";
comboBox1.ValueMember = "animalcode";
}
private void Form1_Load(object sender, EventArgs e)
{
FillCombo_AnimalType();
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if (comboBox1.SelectedIndex > 0 && comboBox1.SelectedValue != null)
{
SqlDataAdapter da = new SqlDataAdapter("Select animalcode, breed From breed Where animalcode=" + comboBox1.SelectedValue.ToString(), Con);
DataTable dt = new DataTable();
da.Fill(dt);
comboBox2.DataSource = dt;
comboBox2.DisplayMember = "breed";
comboBox2.ValueMember = "animalcode";
}
}