j'ai créé une fonction qui lise les données (les lignes ) dans ma fichier excel, pour les insérés dans ma base de données , mais le problème c'est que ma fonction ne s'arrête pas de bouclé sur les lignes de mon fichier excel même si j'ai fait la condition d'arrêt !=Null(ma fonction lise les ligne vide ) , ce qui me génère un exception.
???

voila mon code :
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
 public Void Fonction(string location)
        {
            string Path = location;
            // initialize the Excel Application class
            Excel.ApplicationClass app = new ApplicationClass();
 
            // create the workbook object by opening the excel file.
            Excel.Workbook workBook = app.Workbooks.Open(Path, 0, true , 5,
          "", "", true, Excel.XlPlatform.xlWindows, "\t", false, false,
          0, true);
 
            // get the active worksheet using sheet name or active sheet
            Excel.Worksheet workSheet = (Excel.Worksheet)workBook.ActiveSheet;
            int index = 0;
            object rowIndex = 2;//start line    
            object colIndex3 = 1;
 
            try
            {
                while ((string)((Excel.Range)workSheet.Cells[rowIndex, colIndex3]).Value2 != null)
                {
                    rowIndex = 2 + index;
                    string Champ = ((Excel.Range)workSheet.Cells[rowIndex, colIndex3]).Value2.ToString();
// ma fonction qui fait les insertions dans ma base de données
                    mafonction.insert(Champ );
                    ++index;
                }
         }
         catch (Exception ex)
         {app.Quit(); }
}