当我选择另一个combobox1时,我试图从数据库中的数据填充一个combobox5,这是我正在尝试解决问题的代码。
void FillCombo3()
{
SqlConnection conn = new SqlConnection(myconnstring);
string sql = "SELECT * FROM Section ";
SqlCommand cmd = new SqlCommand(sql, conn);
SqlDataReader myReader;
try
{
conn.Open();
myReader = cmd.ExecuteReader();
DataTable dt = new DataTable();
while (myReader.Read())
{
if(comboBox1.SelectedItem.ToString() == "ClassName")
{
comboBox5.Items.Add("SectionName");
}
}
}
catch (Exception ex)
{
Console.WriteLine("Error is", ex);
}
}