在组合框wpf中更改选择时无法获得值

时间:2015-03-16 19:05:55

标签: c# wpf

我试图在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);
    }
}

如果我试图将消息框显示为显示组合框项目名称,则显示空白框

1 个答案:

答案 0 :(得分:0)

尝试cmbUndrGradu.SelectedItem.ToString()