Bonjour à tous !
Je dois réaliser un projet en C# qui utilise SQLite. J'ai des formulaires que l'utilisateur doit remplir et lorsqu'il clique sur "enregistrer", la base de donnée SQLite doit être mise à jour.
J'ai chercher (presque) partout sur le net, je n'ai rien trouvé... Donc en désespoire de cause, je me tourne vers vous en espérant que qqun ait déjà travailler avec ça !!!
Je précise que je débute en C# et que j'avais utiliser SQLite avec Java sans trop de problèmes, mais là, je sèche !
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
 
//Connection avec la base de donnee EventManager
public static DataTable GetDataTable (string sql)
    {
        DataTable dt = new DataTable();
 
        try
 
        {
 
        SQLiteConnection cnn = new SQLiteConnection("DataSource=C:/Users/Admin/Desktop/eiaj/projet:EquestrianEventManager.s3db");
 
        cnn.Open();
 
        SQLiteCommand mycommand = new SQLiteCommand(cnn);
 
        mycommand.CommandText = sql;
 
        SQLiteDataReader reader = mycommand.ExecuteReader();
 
        dt.Load(reader);
 
        reader.Close();
 
        cnn.Close();
 
        }
 
        catch
 
        {
 
            // Catching exceptions is for communists
            Console.WriteLine ("error");
 
        }
 
    return dt;
 
    }
 
    public static int ExecuteNonQuery(string sql)
 
    {
 
    SQLiteConnection cnn = new SQLiteConnection("DataSource=C:/Desktop/projet:EventManager.s3db");
 
    cnn.Open();
 
    SQLiteCommand mycommand = new SQLiteCommand(cnn);
 
    mycommand.CommandText = sql;
 
    int rowsUpdated = mycommand.ExecuteNonQuery();
 
    cnn.Close();
 
    return rowsUpdated;
 
    }
 
    public static string ExecuteScalar(string sql)
 
    {
 
    SQLiteConnection cnn = new SQLiteConnection("DataSource=C:/Desktop/projet:EventManager.s3db");
 
    cnn.Open();
 
    SQLiteCommand mycommand = new SQLiteCommand(cnn);
 
    mycommand.CommandText = sql;
 
    object value = mycommand.ExecuteScalar();
 
    cnn.Close();
 
    if (value != null)
 
    {
 
        return value.ToString();
 
    }
 
    return "";
 
    }
 
 
// Récupérer le contenu du textBox_Nom du formulaire
private void button_enregistrer_Click(object sender, EventArgs e)
    {
        string essai;
        essai = textBox_Nom.Text;
    }
Voilà ce que j'ai fait. Il n'a pas d'erreur, mais rien ne se passe bien sûr ! Il faut établir un lien, apparemment peut-être avec des hash table comme en java, je ne sais pas... Le seul tuto que j'ai trouvé sur le net vraiment intéressant (ou qui en a l'air) est payant...
Je vous remercie déjà mille fois pour votre aide...