我想在表单上填充一个 ComboBox。我有为我的组合框获取数据的存储过程。我的代码如下。问题是我的组合框没有被填充。当我单步执行代码时,它会到达“reader = sc.ExecuteReader();” 行并且不执行 Pop_ComboBox() 中的任何后续行。存储过程返回“ID”和“描述”(仅)。我究竟做错了什么?
private void frmInput_Load(object sender, EventArgs e)
{
//Connect to the db
this.sqlConn = new SqlConnection("Server=\"our_server";Database=\"Astra\";Trusted_Connection=yes;");
//Populate the Equipment Type Listbox
Pop_ComboBox("exec uspASTRA_GetEquipTypeList;", cboEquipType);
}
private void Pop_ComboBox(string sQuery, ComboBox NameOfcbo)
{
SqlCommand sc = new SqlCommand(sQuery, this.sqlConn);
SqlDataReader reader;
reader = sc.ExecuteReader();
DataTable dt = new DataTable();
dt.Columns.Add("ID", typeof(int));
dt.Columns.Add("Description", typeof(string));
dt.Load(reader);
NameOfcbo.ValueMember = "ID";
NameOfcbo.DisplayMember = "Description";
NameOfcbo.DataSource = dt;
}