Option Strict On
Option Explicit On
Imports System.Data.OleDb
Public Class Form1
Dim pathbase As String = "C:\Users\CS_JMO\desktop\Temp\"
Dim filebase As String = pathbase & "Database11.accdb"
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
readDatabase()
End Sub
Sub readDatabase()
Dim connStr As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & filebase
Using conn As New OleDbConnection(connStr)
conn.Open()
Dim ds As New DataSet
Dim sql As New OleDbDataAdapter(" SELECT nclient,nomclient,nfacture,montantfacture, datefacture" & _
" FROM client_facture", conn)
sql.Fill(ds, "client_facture")
conn.Close()
Dim rows As DataTable = ds.Tables("client_facture")
Dim query = From row In rows.AsEnumerable()
Group row By nclient = row.Field(Of Int32)("nclient") Into nclientGroup = Group
Select New With {
Key nclient,
.nomclient = nclientGroup.Select(Function(r) r.Field(Of String)("nomclient")),
.nfacture = String.Join("-", nclientGroup.Select(Function(r) r.Field(Of String)("nfacture"))),
.montantfacture = nclientGroup.Sum(Function(r) r.Field(Of Int32)("montantfacture")),
.datefacture = nclientGroup.Select(Function(r) r.Field(Of Date)("datefacture"))
}
For Each x In query
MessageBox.Show("nclient=" & x.nclient & Environment.NewLine & _
"nomclient=" & x.nomclient.First & Environment.NewLine & _
"nfacture=" & x.nfacture & Environment.NewLine & _
"montantfacture=" & x.montantfacture & Environment.NewLine & _
"datefacture=" & x.datefacture.First)
Next
End Using
End Sub
End Class
Public Function RecupParticipant(projet As Long) As String
Dim res As DAO.Recordset
Dim SQL As String
'Selectionne les participant du projet
SQL = "SELECT nclient FROM client_facture WHERE nfacture =" & projet
Set res = CurrentDb.OpenRecordset(SQL)
'Concatene les différents enregistrement
While Not res.EOF
RecupParticipant = RecupParticipant & res.Fields(0).Value & " "
res.MoveNext
Wend
'Enleve le dernier espace
RecupParticipant = Left(RecupParticipant, Len(RecupParticipant) - 1)
'libere la mémoire
Set res = Nothing
End Function
Private Sub Command1_Click()
Dim db As Database
Dim rs As DAO.Recordset
Dim SQL As String
Set db = OpenDatabase("C:\facture.mdb")
SQL = "SELECT nclient,nomclient,RecupParticipant(nfacture),sum(montantfacture) FROM client_facture group by nclient,nomclient"
Set rs = db.OpenRecordset(SQL)
SQL = "SELECT nclient,nomclient,RecupParticipant(nfacture),sum(montantfacture) FROM client_facture group by nclient,nomclient"
12 févr. 2017 à 02:20
je ne te corrigerai point car les bases de données et moi cela fait deux !
Il faut dire que je code en VB net pour mon plaisir et n'ayant jamais eu besoin de bases de données je ne m'y suis jamais intéressé de près .
Pas envie de dire des bêtises et d'induire en erreur les personnes qui viennent chercher de l'aide !
Bonne programmation à toi
12 févr. 2017 à 13:42
Un peu pareil pour moi, du coup j'aurais tendance à charger tout le contenu de la base de données dans une collection et faire du Linq dessus après.