使用DataTable在数据库中显示lisbtox元素

时间:2015-12-19 01:33:27

标签: c# sql wpf datatable listbox

m trying to show elements from my database "Worker" in a listbox in a WPF,I want to do this using a DataTable, I检查过我的数据表包含数据库中的元素,问题是尝试在列表框中显示这些元素,列表框没有t show anything, it只是空白。这是我的代码:

  private void MainWindow_Loaded(object sender, RoutedEventArgs e)
    {
        cmd.Connection = con;
         DataTable mydatatable = GetDataTable();
         listBoxListNames.ItemsSource = mydatatable.ToString();
         listBoxListNames.SelectedValuePath = "id";
         listBoxListNames.DisplayMemberPath = "name".ToString();          
        ShowDatabase();
    }

0 个答案:

没有答案