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 41 42 43 44 45 46 47 48 49 50 51 52 53 54
| using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using System.Data.SQLite;
namespace BaseSQLiteTest
{
public partial class Form1 : Form
{
private string pathDB = Path.Combine(Application.StartupPath, "test.qdb");
private SQLiteConnection conn;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
string s = "Data Source={0}; Version=3; New=False; Compress=True;";
this.conn = new SQLiteConnection(String.Format(s, this.pathDB));
this.conn.Open();
MessageBox.Show("OK");
SQLiteDataAdapter da = new SQLiteDataAdapter();
da.SelectCommand = new SQLiteCommand("SELECT * FROM Articles", this.conn);
DataSet ds = new DataSet();
da.Fill(ds, "Articles");
DataTable dt = ds.Tables["Articles"];
foreach (DataRow row in dt.Rows)
{
listBox1.Items.Add(row["Description"]);
}
}
catch (Exception)
{
MessageBox.Show("Erreur");
}
}
}
} |
Partager