1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
// chemin de la base de données
string dbPath = "C:\\Users\\janfi\\Google Drive\\PROGRAMMATION\\COMPTA\\WindowsFormsApp1\\compta.db";
public Form1()
{
InitializeComponent();
}
//Au chargement du programme
private void Form1_Load(object sender, EventArgs e)
{
// on ouvre la table SQLITE pour afficher les enregistrements dans une grille
SQLiteConnection connection = new SQLiteConnection("DataSource=" + dbPath);
connection.Open();
SQLiteCommand command = new SQLiteCommand(connection)
{
CommandText = "SELECT DATE, LIBELLE, MONTANT, CATEGORIE, SOUS_CATEGORIE, COMPLEMENT, SOLDE from compte ORDER BY ID DESC"
};
using (SQLiteDataReader sdr = command.ExecuteReader())
{
//create a new Database
DataTable table = new DataTable();
//LOAD DATAREADER INTO THE DATATABLE
table.Load(sdr);
sdr.Close();
connection.Close();
//on affiche les données lues dans la grille d'affichage
dataGridView1.DataSource = table;
}
}
}
} |
Partager