我试图在wpf中从组合框中更改选择后立即更新数据网格
private void cmbBatchNo_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
try
{
string CmdString = "SELECT Name FROM StudentReg WHERE Course = '" +
cmbUndrGradu.Text + "' and Batch_No = '" + cmbBatchNo.Text + "' ";
SqlCommand cmd = new SqlCommand(CmdString, sc);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataTable dt = new DataTable("Employee");
sda.Fill(dt);
StdAttendence.ItemsSource = dt.DefaultView;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
如果我试图将消息框显示为显示组合框项目名称,则显示空白框
答案 0 :(得分:0)
尝试cmbUndrGradu.SelectedItem.ToString()
。