我想在选择无线电选项后在组合框内的数据库中显示项目。当我尝试这个时候,组合框中没有显示任何内容。请帮忙使用数据填充组合框
private void chkDetailsButton_Click(object sender, EventArgs e)
{
if (radioButtonA.Checked)
{
OleDbConnection connect = db.dbConnect();
try
{
connect.Open();
MessageBox.Show("Opened");
OleDbCommand command = new OleDbCommand();
command.Connection = connect;
command.CommandText = "Select * from Categories";
DataTable dt = new DataTable();
for (int i = 0; i < dt.Rows.Count; i++)
{
cmbDisplay.Items.Add(dt.Rows[i]["SeatNo"]);
}
}
catch (Exception ex)
{
MessageBox.Show("Exception in Database" + ex);
}
finally
{
connect.Close();
}
}
}
你尝试调试代码? – 2012-08-10 09:51:37
是的,我做了,它连接到数据库,但不显示SeatNo列中的项目 – 2012-08-10 09:52:52
这是WinForms还是ASP.Net?如果你可以连接,那dt.Rows.Count是什么?您似乎没有将任何数据放入数据表中! – dash 2012-08-10 09:53:48