B
Bajtitou
Guest
Hi,
I am using a ms Access databble .
I want to get the total of datagridview showing in the last line,
I try with this code but I don't get The last Row.
This Is the code :
Public Class MainForm
Public Opst As New OperationsTableauDeBord
Private Sub MainForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
ShowDataALLPontes1()
End Sub
DataTale:
Public Function DataLesPontes1() As DataTable
Dim selectStatement As String =
<SQL>
SELECT
LesPontes.CID, LesPontes.Pontes,
LesPontes.Cage, LesPontes.Race,
dbFécondation.ŒufsFécondés,dbEclosion.ŒufsEclos,
dbMortalité.MortEnNids, dbMortalité.OiseauxSevrés
FROM dbMortalité RIGHT JOIN
(dbSevrages RIGHT JOIN
(dbEclosion RIGHT JOIN
(dbFécondation RIGHT JOIN LesPontes
ON dbFécondation.CoupleID = LesPontes.CoupleID)
ON dbEclosion.CoupleID = LesPontes.CoupleID)
ON dbSevrages.CoupleID = LesPontes.CoupleID)
ON dbMortalité.CoupleID = LesPontes.CoupleID order by lesPontes.CID;
</SQL>.Value
Using cn As New OleDb.OleDbConnection With
{
.ConnectionString = Builder.ConnectionString
}
Using cmd As New OleDb.OleDbCommand With {.Connection = cn}
cmd.CommandText = selectStatement
Dim dt As New DataTable
cn.Open()
dt.Load(cmd.ExecuteReader)
Return dt
End Using
End Using
End Function
The code:
Private Sub ShowDataALLPontes1()
Dgw.DataSource = Opst.DataLesPontes1()
Dim Sum As Integer = 0
Dim Sum1 As Integer = 0
Dim Sum2 As Integer = 0
Dim Sum3 As Integer = 0
For i As Integer = 0 To Dgw.Rows.Count - 1
Sum += If(Not Convert.IsDBNull(Dgw.Rows(i).Cells(4).Value), Convert.ToInt32(Dgw.Rows(i).Cells(4).Value), 0)
Sum1 += If(Not Convert.IsDBNull(Dgw.Rows(i).Cells(5).Value), Convert.ToInt32(Dgw.Rows(i).Cells(5).Value), 0)
Sum2 += If(Not Convert.IsDBNull(Dgw.Rows(i).Cells(6).Value), Convert.ToInt32(Dgw.Rows(i).Cells(6).Value), 0)
Sum3 += If(Not Convert.IsDBNull(Dgw.Rows(i).Cells(7).Value), Convert.ToInt32(Dgw.Rows(i).Cells(7).Value), 0)
Next
Dgw("ŒufsFécondés", Dgw.Rows.Count - 1).Value = Sum
Dgw("ŒufsEclos", Dgw.Rows.Count - 1).Value = Sum1
Dgw("MortEnNids", Dgw.Rows.Count - 1).Value = Sum2
Dgw("OiseauxSevrés", Dgw.Rows.Count - 1).Value = Sum3
Dgw("Race", Dgw.Rows.Count - 1).Value = "TOTAL"
Dgw.Rows(Dgw.Rows.Count - 1).DefaultCellStyle.BackColor = Color.YellowGreen
Dgw.Rows(Dgw.Rows.Count - 1).DefaultCellStyle.ForeColor = Color.Black
Dgw.Rows(Dgw.Rows.Count - 1).DefaultCellStyle.Font = New Font("Segoe UI", 9, (FontStyle.Bold))
End Sub
This Is a screenshot:
So Thank you Very Much and Best Regards.
Continue reading...
I am using a ms Access databble .
I want to get the total of datagridview showing in the last line,
I try with this code but I don't get The last Row.
This Is the code :
Public Class MainForm
Public Opst As New OperationsTableauDeBord
Private Sub MainForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
ShowDataALLPontes1()
End Sub
DataTale:
Public Function DataLesPontes1() As DataTable
Dim selectStatement As String =
<SQL>
SELECT
LesPontes.CID, LesPontes.Pontes,
LesPontes.Cage, LesPontes.Race,
dbFécondation.ŒufsFécondés,dbEclosion.ŒufsEclos,
dbMortalité.MortEnNids, dbMortalité.OiseauxSevrés
FROM dbMortalité RIGHT JOIN
(dbSevrages RIGHT JOIN
(dbEclosion RIGHT JOIN
(dbFécondation RIGHT JOIN LesPontes
ON dbFécondation.CoupleID = LesPontes.CoupleID)
ON dbEclosion.CoupleID = LesPontes.CoupleID)
ON dbSevrages.CoupleID = LesPontes.CoupleID)
ON dbMortalité.CoupleID = LesPontes.CoupleID order by lesPontes.CID;
</SQL>.Value
Using cn As New OleDb.OleDbConnection With
{
.ConnectionString = Builder.ConnectionString
}
Using cmd As New OleDb.OleDbCommand With {.Connection = cn}
cmd.CommandText = selectStatement
Dim dt As New DataTable
cn.Open()
dt.Load(cmd.ExecuteReader)
Return dt
End Using
End Using
End Function
The code:
Private Sub ShowDataALLPontes1()
Dgw.DataSource = Opst.DataLesPontes1()
Dim Sum As Integer = 0
Dim Sum1 As Integer = 0
Dim Sum2 As Integer = 0
Dim Sum3 As Integer = 0
For i As Integer = 0 To Dgw.Rows.Count - 1
Sum += If(Not Convert.IsDBNull(Dgw.Rows(i).Cells(4).Value), Convert.ToInt32(Dgw.Rows(i).Cells(4).Value), 0)
Sum1 += If(Not Convert.IsDBNull(Dgw.Rows(i).Cells(5).Value), Convert.ToInt32(Dgw.Rows(i).Cells(5).Value), 0)
Sum2 += If(Not Convert.IsDBNull(Dgw.Rows(i).Cells(6).Value), Convert.ToInt32(Dgw.Rows(i).Cells(6).Value), 0)
Sum3 += If(Not Convert.IsDBNull(Dgw.Rows(i).Cells(7).Value), Convert.ToInt32(Dgw.Rows(i).Cells(7).Value), 0)
Next
Dgw("ŒufsFécondés", Dgw.Rows.Count - 1).Value = Sum
Dgw("ŒufsEclos", Dgw.Rows.Count - 1).Value = Sum1
Dgw("MortEnNids", Dgw.Rows.Count - 1).Value = Sum2
Dgw("OiseauxSevrés", Dgw.Rows.Count - 1).Value = Sum3
Dgw("Race", Dgw.Rows.Count - 1).Value = "TOTAL"
Dgw.Rows(Dgw.Rows.Count - 1).DefaultCellStyle.BackColor = Color.YellowGreen
Dgw.Rows(Dgw.Rows.Count - 1).DefaultCellStyle.ForeColor = Color.Black
Dgw.Rows(Dgw.Rows.Count - 1).DefaultCellStyle.Font = New Font("Segoe UI", 9, (FontStyle.Bold))
End Sub
This Is a screenshot:
So Thank you Very Much and Best Regards.
Continue reading...