Dim cn As New Connection
Dim rs As New Recordset'-- fungsinya dimana colom yang sudah dijumlahkan akan ditampilkan... Private Sub cmdHitungKolom_Click() Text1.Text = 0 Text1.Text = Kalkulasi(rs, "unitprice") End Sub
'----- fungsinya utuk 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 Kalkulasi = Total End Function
http://WeeklyYouthPay.com/?ref=421748
No comments:
Post a Comment