download gratis video tutorial vb 6 dan vb.net plus contoh aplikasi

cara menjumlahkan data kolom dalam datagridview

 

 

 


Imports System.Data.SqlClient

 

Public Class sqlserver2005

Dim conn As SqlConnection
Dim da As SqlDataAdapter
Dim ds As DataSet

 

Sub koneksi()
conn = New SqlConnection("data source=user-pc\sqlexpress;initial catalog=mydbagain;integrated security=true")
conn.Open()

End Sub

 

Sub Summary()
Dim x As Integer
For line As Integer = 0 To DGV.RowCount - 1
x = x + DGV.Rows(line).Cells(4).Value
Next
TextBox1.Text = x
End Sub

 

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Call koneksi()
da = New SqlDataAdapter("select * from tblbarang", conn)
ds = New DataSet
da.Fill(ds)
DGV.DataSource = ds.Tables(0)
DGV.ReadOnly = True

Call Summary()

End Sub

End Class