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
| Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim cmd As SqlCommand
Dim DtSet As DataSet
Dim DtAdapter As SqlDataAdapter
Dim connection As New SqlConnection
Try
connection = New SqlConnection()
connection.ConnectionString = "Data Source=FRSESQL1;Initial Catalog=GTP;Integrated Security=True"
'Ouverture
connection.Open()
cmd = New SqlCommand
cmd.Connection = connection
cmd.CommandText = "select a.dat date , e.categ, f.categlib, a.secid code_activite," & _
" b.libsec lib_activite, a.s_secid code_sous_activite, c.s_libsec lib_sous_activite," & _
" cast(REPLACE (cast(sum(dbo.ST_HC(d.C9)) as char(10)) , '.' , ',' ) as char(12)) tps_rh," & _
" cast(REPLACE (cast(sum(dbo.ST_HC(a.tval)) as char(10)) , '.' , ',' ) as char(12)) tps_act" & _
" from sec b, sousec c, persvar e, categorie f, comptj d, cptsec a,pers g " & _
" where(a.secid = b.secid And a.s_secid = c.s_secid And b.secid = c.secid)" & _
" and (a.matric=d.matric and a.dat=d.dat )" & _
" and (a.matric=e.matric and a.dat between e.dsitud and e.dsituf )" & _
" and (e.categ=f.categ and e.categ!=4000) and d.dat between " & _
DateTimePicker1.Value & " and " & DateTimePicker2.Value & " group by a.dat, a.secid, b.libsec, a.s_secid, c.s_libsec, e.categ, f.categlib"
'Création du DataSet
DtSet = New DataSet
' Création du DataAdapter
DtAdapter = New SqlDataAdapter()
DtAdapter.SelectCommand = cmd
DtAdapter.Fill(DtSet, "My_Table")
Me.DataGridView1.DataSource = DtSet
Me.DataGridView1.DataMember = "My_Table"
Catch ex As Exception
MessageBox.Show(ex.ToString, "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Error)
Finally
'Fermer la connection
connection.Close()
End Try
End Sub |
Partager