Comment alimenter un dataSet

Résolu
cs_JMO Messages postés 1854 Date d'inscription jeudi 23 mai 2002 Statut Membre Dernière intervention 24 juin 2018 - 6 avril 2015 à 21:14
cs_JMO Messages postés 1854 Date d'inscription jeudi 23 mai 2002 Statut Membre Dernière intervention 24 juin 2018 - 7 avril 2015 à 10:45
Bonjour le Forum,

Fichier Excel

A partir de ce fichier, je créé un DataSet.
        
Dim MyConnexionCGN As OleDbConnection = New OleDbConnection _
(ConnectingExcel(MyFileCGN, "HDR=YES"))
Dim MyQueryCGN As String = " SELECT [Environnement], [Application], [Job] " & _
" FROM [Informations_CGN$] WHERE [Job] IS NOT NULL " & _
" ORDER BY [Environnement] ASC, [Application] ASC, [Job] ASC "
MyConnexionCGN.Open()
da = New OleDb.OleDbDataAdapter(MyQueryCGN, MyConnexionCGN)
da.Fill(ds, "CGN")
MyConnexionCGN.Close()


da -> Public da As OleDb.OleDbDataAdapter
ds -> Public ds As DataSet = New DataSet
Le DataSet "ds.Tables("CGN")" est créé correctement.

Maintenant, je parcours un répertoire pour récupérer tous les items.
Dim ds As DataSet = New DataSet("Disque")

For Each foundFile As String In My.Computer.FileSystem.GetFiles(MyPathConsignes)
Dim lastpart As String = foundFile.Substring(foundFile.LastIndexOf("\") + 1)
lastpart = Replace(lastpart.ToString, ".docx", vbNullString)

Dim cells As String() = lastpart.Split(New Char() {Convert.ToChar(46)}, StringSplitOptions.None)

Dim MyFile As String = cells(1) & vbTab & cells(2) & vbTab & cells(3)

Me.RichTextBox1.AppendText(dt(MyDt) & vbTab & MyFile)
System.Windows.Forms.Application.DoEvents()
Next foundFile


Pour la 1ère itération,
Cells(1) contient "SV_ASIP"
Cells(2) contient "ANNUELLE"
Cells(3) contient "ASIABASCU01"


Ma question:
Comment alimenter le DataSet("Disque") ???
Mon souhait étant d'extraire le nom des fichiers présents sur disque mais non présents dans le fichier Excel via :
' Comparaison fichiers disque et contenu du fichier Informations_CGN
' Contrôle fichiers disques non présents dans Informations_CGN
Dim items = ds.Tables("Disque").AsEnumerable().Except(ds.Tables("CGN").AsEnumerable(), _
' DataRowComparer.Default)


Merci pour suggestions,
jean-marc

2 réponses

cs_JMO Messages postés 1854 Date d'inscription jeudi 23 mai 2002 Statut Membre Dernière intervention 24 juin 2018 27
7 avril 2015 à 10:17
Bonjour le forum,

Avec
' Création DataTable
Dim dsDisk As DataTable = New DataTable("Disque")
dsDisk.Columns.Add("Environnement", GetType(String))
dsDisk.Columns.Add("Application", GetType(String))
dsDisk.Columns.Add("Job", GetType(String))

For Each foundFile As String In My.Computer.FileSystem.GetFiles(MyPathConsignes)
Dim lastpart As String = foundFile.Substring(foundFile.LastIndexOf("\") + 1)
lastpart = Replace(lastpart.ToString, ".docx", vbNullString)

Dim cells As String() = lastpart.Split(New Char() {Convert.ToChar(46)}, StringSplitOptions.None)
dsDisk.Rows.Add(cells(1), cells(2), cells(3))
Next foundFile

'Analyse des DataTable
For Each row As DataRow In dsDisk.Rows()
Me.RichTextBox1.AppendText(dt(MyDt) & dt(MyDt) & "Contrôle dsDisk.Rows()")
Me.RichTextBox1.AppendText(dt(MyDt) & _
row("Environnement").ToString & vbTab & _
row("Application").ToString & vbTab & _
row("Job").ToString)
Exit For ' pour contrôle
Next


dsDisk n'est pas un DataTable mais un DataRow.
La boucle For Each .... In dsDisk.Tables("Disque").Rows() me retourne une erreur.

Comment m'y prendre pour obtenir un DataTable ???


jean-marc
0
cs_JMO Messages postés 1854 Date d'inscription jeudi 23 mai 2002 Statut Membre Dernière intervention 24 juin 2018 27
7 avril 2015 à 10:45
Problème résolu !!!

Correction de la déclaration de la variable
Dim TableDisk As DataTable = New DataTable


et pour comparer les deux tables
Dim TableError As DataTable = TableDisk.AsEnumerable().Except(ds.Tables("CGN").AsEnumerable(), _
DataRowComparer.Default) _
.CopyToDataTable()
If TableError.Rows.Count = 0 Then

jean-marc
0
Rejoignez-nous