Bonjour,

J'essaye de comprendre comment me servir d'une base sqlite.
curieusement toute la boucle passe, pas d'erreur, mais quand j'ouvre le résultat j'ai que 7990 enregistrement ??

code concernant la classe aux complet.
note: using static PauseSleep.PauseSleep; est une classe externe.

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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
 
using System;
using System.Data.SQLite;
using System.Collections.Generic;
using static PauseSleep.PauseSleep;
 
namespace NSqlSharp
{
    public class SqlCSharp
    {
        private string pdb = "";
        // variable pour les table, les insertions ce fond dans la methode
        //il existe peux être un moyen de faire les deux en même temps ?
        private string sql_FichierNormal = "CREATE TABLE IF NOT EXISTS 'T_FichierNormal' ( " +
                              "  'id' INTEGER PRIMARY KEY, " +
                              "  'fullpath' TEXT NOT NULL, " +
                              "  'sizefile' int NOT NULL" +
                              ");";
 
 
        private string sql_FichierErreur = "CREATE TABLE IF NOT EXISTS 'T_FichierErreur' ( " +
                              "  'id' INTEGER PRIMARY KEY, " +
                              "  'fullpath' TEXT NOT NULL, " +
                              "  'errortype' TEXT NOT NULL " +
                              ");";
        private string sql_Sauvegarde = "CREATE TABLE IF NOT EXISTS 'T_Sauvegarde' ( " +
                              "  'id' INTEGER PRIMARY KEY, " +
                              "  'date' TEXT NOT NULL, " +
                              "  'commentaire' TEXT " +
                              ");";
        //constructeur
        public SqlCSharp(string pathdatabase) 
        {
            // supprime et cree  si elle existe (ou pas) et les table si besoins
            pdb = @"Data Source=" + pathdatabase + ";Version=3;";
            SQLiteConnection.CreateFile(pathdatabase);
            SqlCreateTable(sql_FichierNormal);
            SqlCreateTable(sql_FichierErreur);
            SqlCreateTable(sql_Sauvegarde);
        }
        private void Sql_Printerror(ref SQLiteException sqle,ref string pdb) 
        {
            Console.WriteLine("************************************************");
            Console.WriteLine("Erreur sur la base de donnée ");
            Console.WriteLine(pdb);
            Console.WriteLine(sqle);
            Console.WriteLine("************************************************");
 
            Sleep(20);
            // Sql_Printerror(ref sqle, ref pdb, ref sql);
        }
 
 
        //execute les requetes pour la creation des tables
        private void SqlCreateTable(string sql) {
            try
            {
                using (SQLiteConnection connection = new SQLiteConnection(pdb))
                {
 
                    connection.Open();
                    using (SQLiteCommand command = connection.CreateCommand())
                    {
                        SQLiteParameter myparam = new SQLiteParameter();
                        command.CommandType = System.Data.CommandType.Text;
                        command.CommandText = sql;
                        command.ExecuteNonQuery();
                    }                                       
                    connection.Close();
                }
            }
            catch (SQLiteException sqle)
            {
                Sql_Printerror(ref sqle, ref pdb);
            }
        }
        //insertion des données sous forme de liste 
        public void T_FichierNormal(ref List<string> l_fullpath,
                                ref List<string> l_errortype,
                                ref List<string> l_fullpatherror,
                                ref List<long> l_sizefile,
                                ref string s_path)
        {
            try
            {
                using (SQLiteConnection connection = new SQLiteConnection(pdb))
                {
 
                    connection.Open();
 
                    using (SQLiteCommand command = connection.CreateCommand())
                    {
 
                        SQLiteParameter myparam = new SQLiteParameter();
 
                        for (int i = 0; i < l_fullpath.Count; i++)
                        {
                            string sql = "insert into T_FichierNormal " +
                                            "(fullpath, sizefile) values ('" +
                                            l_fullpath[i] + "', '" + l_sizefile[i] + "')";
 
                            command.CommandType = System.Data.CommandType.Text;
                            command.CommandText = sql;
                            var trans = connection.BeginTransaction();
                            command.ExecuteNonQuery();
 
                            trans.Commit();
                            Console.WriteLine(l_fullpath.Count + " : " + i + " : " + l_fullpath[i]);
                            i++;
                        }
                    }
 
                    connection.Close();
                }
            }
            catch (SQLiteException sqle)
            {
                Sql_Printerror(ref sqle, ref pdb);
            }
 
        }
    }
}
merci d'avance