Menjumlahkan Kolom DataGrid di Visual Basic

Mari kita Belajar Cara menjumlahkan data di vb menggunakan data Grid.. Bikin Tampilan Seperti Gambar diSamping Ini.
perintah Koding Dibawah ini Silakan Copy Paste Codingngnya
-- Perintah dibawah Ini utuk Pehubung Koneksinya..
Dim cn As New Connection
Dim rs As New Recordset


Private Sub cmdKolom_Click()
  Text1.Text = 0
  Text1.Text = jumlah(rs, "unitprice")
End Sub

----  Coneksi pehubung Ke database
Private Sub Form_Load()
  cn.ConnectionString = "Provider=SQLOLEDB;Server=rudi;Initial Catalog=northwind;UID=sa;PWD=123"
  cn.Open
 
  rs.CursorLocation = adUseClient
  rs.Open "select * from products where discontinued=1", cn
  Set DataGrid1.DataSource = rs

End Sub


'---fungsi ini digunakan utk menghitung jumlah data yg ada pd field
Private Function Kalkulasi(oRs As Recordset, sField As String) As Double
  Dim Total As Double
  Total = 0
  oRs.MoveLast
  oRs.MoveFirst
  Do While oRs.EOF = False
  '---jumlahkan data berdasarkan field yg dipanggil
  Total = Total + oRs(sField)
  oRs.MoveNext
  Loop
 
  jumlah = Total
End Function



No comments:

Post a Comment

VIRUS

Do not open any attachment received from the unknown or untrusted sender Do not plug in any external USB drive into the company ...