After looking for in several topics I am still without answer. I just make a test with Sqlite in C#. But my program through an System.AccessViolationException and I can't figure it out.
I created the eleves.sqlite with an Mozilla Extension. And in my document folder so normaly I have all right to get it.
My Simple Code :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using MahApps.Metro.Controls;
using Finisar.SQLite;
namespace GestionEleves
{
/// <summary>
/// Logique d'interaction pour MainWindow.xaml
/// </summary>
public partial class MainWindow : MetroWindow
{
public MainWindow()
{
InitializeComponent();
test_connexion_db();
}
private void reinitialiser()
{
// Mise à jours des élèves
}
private void test_connexion_db()
{
// We use these three SQLite objects:
SQLiteConnection sqlite_conn;
SQLiteCommand sqlite_cmd;
SQLiteDataReader sqlite_datareader;
// create a new database connection:
sqlite_conn = new SQLiteConnection("Data Source=eleve.sqlite;Version=3;New=False;");
// open the connection:
sqlite_conn.Open();
// create a new SQL command:
sqlite_cmd = sqlite_conn.CreateCommand();
// But how do we read something out of our table ?
// First lets build a SQL-Query again:
sqlite_cmd.CommandText = "SELECT * FROM eleve";
// Now the SQLiteCommand object can give us a DataReader-Object:
sqlite_datareader = sqlite_cmd.ExecuteReader();
// The SQLiteDataReader allows us to run through the result lines:
while (sqlite_datareader.Read()) // Read() returns true if there is still a result line to read
{
// Print out the content of the text field:
lb_eleves.Items.Clear();
lb_eleves.Items.Add(sqlite_datareader["nom"] + " " + sqlite_datareader["prenom"]);
}
// We are ready, now lets cleanup and close our connection:
sqlite_conn.Close();
}
}
}
The Exception is throw at line => sqlite_conn.Open();
Thanks in advance for your help ;-) Antoine
Aucun commentaire:
Enregistrer un commentaire