Делаю приложение для управления своей БД в WPF проекте.Хочу сделать вывод любой таблицы по нажатию RadioButton.У RadioButton дочерний элемент Label.В нем содержится название таблицы.Вот это название нужно вставлять вместо Table в функции(2 строки). Я знаю,что можно обращаться к кнопке через sender,но как обратиться к дочернему элементу кнопки не знаю.
Функция для вывода таблицы БД:
private void LibraryView(object sender, RoutedEventArgs e)
{
SqlConnection connection = new SqlConnection(@"Data Source=LAPTOP-P14D9V4Q; Initial Catalog=Library; Integrated Security=True");
connection.Open();
string cmd = "SELECT * FROM Table"; // Из какой таблицы нужен вывод
SqlCommand createCommand = new SqlCommand(cmd, connection);
createCommand.ExecuteNonQuery();
SqlDataAdapter dataAdp = new SqlDataAdapter(createCommand);
DataTable dt = new DataTable("Table"); // В скобках указываем название таблицы
dataAdp.Fill(dt);
StudentsGrid.ItemsSource = dt.DefaultView; // Сам вывод
connection.Close();
}
xaml код:
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
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:Library"
xmlns:SqlServer="clr-namespace:System.Data.Entity.SqlServer;assembly=EntityFramework.SqlServer" x:Class="Library.MainWindow"
mc:Ignorable="d" Height="450" Width="800" ShowInTaskbar="False" Title="Library">
<Grid>
<DataGrid x:Name="StudentsGrid" HorizontalAlignment="Left" Height="301" Margin="333,133,0,0" AutoGenerateColumns="True" VerticalAlignment="Top" Width="467" d:ItemsSource="{d:SampleData ItemCount=5}"/>
<ComboBox x:Name="LibraryObjects" Text="Список обьектов библиотеки" ItemsSource="{Binding Path=ListOfItem}" IsEditable="True" IsReadOnly="True" HorizontalAlignment="Left" Margin="39,54,0,0" VerticalAlignment="Top" Width="209" Height="31" >
<RadioButton Background="#FF0025FA" Width="50" Height="50" MinWidth="50" MinHeight="50" MaxWidth="50" MaxHeight="50" BorderBrush="Black" Checked="LibraryView">
<Label>Libs</Label>
</RadioButton>
<RadioButton Background="#FF0025FA" Width="50" Height="50" MinWidth="50" MinHeight="50" MaxWidth="50" MaxHeight="50" BorderBrush="Black">
<Label>Librarians</Label>
</RadioButton>
<RadioButton Background="#FF0025FA" Width="50" Height="50" MinWidth="50" MinHeight="50" MaxWidth="50" MaxHeight="50" BorderBrush="Black">
<Label>Groups</Label>
</RadioButton>
<RadioButton Background="#FF0025FA" Width="50" Height="50" MinWidth="50" MinHeight="50" MaxWidth="50" MaxHeight="50" BorderBrush="Black">
<Label>Faculties</Label>
</RadioButton>
<RadioButton Background="#FF0025FA" Width="50" Height="50" MinWidth="50" MinHeight="50" MaxWidth="50" MaxHeight="50" BorderBrush="Black">
<Label>Students</Label>
</RadioButton>
<RadioButton Background="#FF0025FA" Width="50" Height="50" MinWidth="50" MinHeight="50" MaxWidth="50" MaxHeight="50" BorderBrush="Black">
<Label>SCards</Label>
</RadioButton>
<RadioButton Background="#FF0025FA" Width="50" Height="50" MinWidth="50" MinHeight="50" MaxWidth="50" MaxHeight="50" BorderBrush="Black">
<Label>Teachers</Label>
</RadioButton>
<RadioButton Background="#FF0025FA" Width="50" Height="50" MinWidth="50" MinHeight="50" MaxWidth="50" MaxHeight="50" BorderBrush="Black">
<Label>TCards</Label>
</RadioButton>
<RadioButton Background="#FF0025FA" Width="50" Height="50" MinWidth="50" MinHeight="50" MaxWidth="50" MaxHeight="50" BorderBrush="Black">
<Label>Departments</Label>
</RadioButton>
<RadioButton Background="#FF0025FA" Width="50" Height="50" MinWidth="50" MinHeight="50" MaxWidth="50" MaxHeight="50" BorderBrush="Black">
<Label>Books</Label>
</RadioButton>
<RadioButton Background="#FF0025FA" Width="50" Height="50" MinWidth="50" MinHeight="50" MaxWidth="50" MaxHeight="50" BorderBrush="Black">
<Label>Authors</Label>
</RadioButton>
<RadioButton Background="#FF0025FA" Width="50" Height="50" MinWidth="50" MinHeight="50" MaxWidth="50" MaxHeight="50" BorderBrush="Black">
<Label>Categories</Label>
</RadioButton>
<RadioButton Background="#FF0025FA" Width="50" Height="50" MinWidth="50" MinHeight="50" MaxWidth="50" MaxHeight="50" BorderBrush="Black">
<Label>Press</Label>
</RadioButton>
<RadioButton Background="#FF0025FA" Width="50" Height="50" MinWidth="50" MinHeight="50" MaxWidth="50" MaxHeight="50" BorderBrush="Black">
<Label>Theme</Label>
</RadioButton>
</ComboBox>
<Button Content="Добавить" HorizontalAlignment="Left" Margin="374,62,0,0" VerticalAlignment="Top" Width="96" Click="Button_Click"/>
<Button Content="Изменить" HorizontalAlignment="Left" Margin="518,62,0,0" VerticalAlignment="Top" Width="96" Click="Button_Click"/>
<Button Content="Удалить" HorizontalAlignment="Left" Margin="655,62,0,0" VerticalAlignment="Top" Width="96" Click="Button_Click"/>
</Grid>
</Window>