具有自动生成列的DataGrid中的列名显示错误

时间:2018-10-12 15:29:54

标签: c# wpf oracle datagrid

我正在对WPF应用程序进行编程,它应该从ORACLE中检索数据,并使用autogeneratecolumns在DataGrid中显示它。 问题在于某些列名只是被错误地表示。仅显示INITIATEDATE而不是INITIATE_DATE的示例。下划线主要被忽略。感谢您的帮助。

<Window x:Class="OPEN_ORDERS_ORACLE_TABLE.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xml:lang="de-DE"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:OPEN_ORDERS_ORACLE_TABLE"
    mc:Ignorable="d"
    Title="MainWindow" Height="450" Width="800" Loaded="Window_Loaded">
    <Grid Height="419" VerticalAlignment="Top">
        <DataGrid x:Name ="DataGrid1" ItemsSource="{Binding}" Margin="10,40,10,70"/>
    </Grid>
</Window>

private void Window_Loaded(object sender, RoutedEventArgs e)
{
    try
    {
        String connectionString = "Data Source=DWH; User Id=readonly; Password=*********;";
        OracleConnection con = new OracleConnection();
        con.ConnectionString = connectionString;
        con.Open();
        OracleCommand cmd = con.CreateCommand();
        cmd.CommandText = "SELECT * FROM AFTERSALES.TBL_OPEN_ORDERS";
        cmd.CommandType = CommandType.Text;
        OracleDataReader dr = cmd.ExecuteReader();
        DataTable dt = new DataTable();
        dt.Load(dr);
        DataGrid1.ItemsSource = dt.DefaultView;
        dr.Close();
        con.Close();
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.ToString());
    }
}

0 个答案:

没有答案