数据在datagrid中显示两次

xeufq47z  于 2021-06-21  发布在  Mysql
关注(0)|答案(0)|浏览(221)

我在xaml代码中创建了如下datagrid:

<DataGrid x:Name="dgSalons" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Height="100" Width="572" ItemsSource="{Binding}" VerticalScrollBarVisibility="Hidden">
   <DataGrid.Columns>
        <DataGridTextColumn Header="ИД" Binding="{Binding Path = id}" Width="*"/> 
        <DataGridTextColumn Header="Назив" Binding="{Binding Path = name}"  Width="*"/>
        <DataGridTextColumn Header="Адреса" Binding="{Binding Path = adress}" Width="*"/>
        <DataGridTextColumn Header="Телефон" Binding="{Binding Path = email}"  Width="*"/>
        <DataGridTextColumn Header="Интернет адреса" Binding="{Binding Path = web_site}" Width="*"/>
        <DataGridTextColumn Header="ПИБ" Binding="{Binding Path = tin}"  Width="*"/>
        <DataGridTextColumn Header="Матични Број" Binding="{Binding Path = uid}"  Width="*"/>
        <DataGridTextColumn Header="Жиро рачун" Binding="{Binding Path = bank_account}"  Width="*"/>
    </DataGrid.Columns> 
</DataGrid>

我试着用mysql的数据填充它,点击“显示”按钮(прикажи):

private void btnShow_Click(object sender, RoutedEventArgs e)
        {
                    string connection = "server=localhost;user id=root; password=root; database=pop-sf40-database";
                    string query = String.Format("SELECT * FROM salons");

                MySqlConnection cn = new MySqlConnection(connection);
                cn.Open();

                MySqlCommand command = new MySqlCommand(query, cn);
                MySqlDataAdapter da = new MySqlDataAdapter(command);

                DataTable data = new DataTable();
                da.Fill(data);
                dgSalons.DataContext = data;
    }

在单击按钮之前,它看起来像这样:

之后呢

如何通过绑定只填充一次单元格?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题