i am using sqlite db file. Installed nuget package in ".net" for using "System.Data.SQLite". To open single table select * from tablename works, but how to display single table if the database has several tables inside it.
c# code
public MainWindow()
{
InitializeComponent();
GetData("SELECT table1 FROM sqlite_master WHERE type='table';");
}
private void GetData(string selectCommand)
{
//Open up a connection to the SQLite file
SQLiteConnection connection = new SQLiteConnection("Data Source=mydb.sqlite;Version=3");
connection.Open();
SQLiteCommand command = new SQLiteCommand(selectCommand, connection);
command.ExecuteNonQuery();
// Create a new data adapter based on the specified query.
_adapter = new SQLiteDataAdapter(command);
_dt = new DataTable("SELECT table1 FROM sqlite_master WHERE type='table';");
//select * from sqlite_master where tbl_name ='table1'
_adapter.Fill(_dt);
//Load data into DataGrid
DataGridSchoolresultaat.ItemsSource = _dt.DefaultView;
//Find the CollectionViewSource you made in the UI
_resultatenViewSource = ((CollectionViewSource)(this.FindResource("resultatenViewSource")));
//Load data into the COllectionViewSource
_resultatenViewSource.Source = _dt;
//Show first row of data in the textboxes
_resultatenViewSource.View.MoveCurrentToFirst();
connection.Close();
}
//xaml
<Window.Resources>
<CollectionViewSource x:Key="resultatenViewSource" Source="{Binding Klanten}"/>
</Window.Resources>
<StackPanel Grid.Row="1" DataContext="{StaticResource resultatenViewSource}">
<TextBlock Margin="0,0,0,10" Text="serialno"></TextBlock>
<TextBox Name="sno" Text="{Binding NaamVak, Mode=TwoWay}"></TextBox>
<TextBlock Margin="0,10,0,10" Text="que"></TextBlock>
<TextBox Name="que" Text="{Binding Score, Mode=TwoWay}"></TextBox>
<TextBlock Margin="0,10,0,10" Text="option1"></TextBlock>
<TextBox Name="opt1" Text="{Binding Datum, Mode=TwoWay}"></TextBox>
<TextBlock Margin="0,10,0,10" Text="option2"></TextBlock>
<TextBox Name="opt2" Text="{Binding Opmerking, Mode=TwoWay}"></TextBox>
<TextBlock Margin="0,10,0,10" Text="option3"></TextBlock>
<TextBox Name="opt3" Text="{Binding Credit, Mode=TwoWay}"></TextBox>
<TextBlock Margin="0,10,0,10" Text="answer"></TextBlock>
<TextBox Name="ans" Text="{Binding id, Mode=TwoWay}"></TextBox>
<TextBlock Margin="0,10,0,10" Text="langid"></TextBlock>
<TextBox Name="lid" Text="{Binding id, Mode=TwoWay}"></TextBox>
<TextBlock Margin="0,10,0,10" Text="subjectid"></TextBlock>
<TextBox Name="sid" Text="{Binding id, Mode=TwoWay}"></TextBox>
<DockPanel Margin="0,10,0,10">
<Button HorizontalAlignment="Left" Padding="10,2,10,2" Content="Refresh" Click="Button_Click_2"></Button>
<Button HorizontalAlignment="Right" Padding="10,2,10,2" Content="Save" Click="Button_Click_3"></Button>
</DockPanel>
</StackPanel>
<DataGrid Margin="25,0,0,0" Name="DataGridSchoolresultaat" Grid.Column="1" Grid.RowSpan="2" AutoGenerateColumns="True"></DataGrid>
Aucun commentaire:
Enregistrer un commentaire