sql = "select '' as NO,Detail,amt,price,(amt*price) as Total from tablename"
da = New OleDbDataAdapter(Sql, Conn)
da.Fill(ds, "product")
If ds.Tables("product").Rows.Count <> 0 Then
With dgvCustomer
.DataSource = ds.Tables("product")
For i as short = 0 To .Rows.Count - 2
.Rows(i).Height = 25
.Rows(i).Cells(0).Value = (i + 1) & "."
Next
End With
End If
Dim cmd As OleDbCommand
Dim reader As OleDbDataReader
Dim da As OleDbDataAdapter
Dim ds As New DataSet
Dim _row, _Amt, _Price, _Total As Integer
Private Sub btn01_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn01.Click
_row += 1
Sql = "select invoice,quantity,cost,(quantity*cost) as Total from ets_invoice_report_total where id=1" ' where แล้วแต่ ต้นไม้แต่ละต้น
cmd = New OleDbCommand(Sql, Conn)
reader = cmd.ExecuteReader
If reader.HasRows Then
While reader.Read
SetData(reader("invoice"), reader("quantity"), reader("cost"), reader("Total"))
End While
End If
reader.Close()
End Sub
Private Sub SetData(ByVal _invoice As String, ByVal _qty As Integer, ByVal _cost As Integer, ByVal _total As Integer)
Dim row As DataRow = ds.Tables("ets_invoice_report_total").NewRow
row("ลำดับ") = _row
row("รายการ") = _invoice
row("จำนวน") = _qty
row("ราคา") = _cost
row("รวมเงิน") = _total
ds.Tables("ets_invoice_report_total").Rows.Add(row)
fncCal()
End Sub
Private Sub fncCal()
_Amt = 0
_Price = 0
_Total = 0
For i As Short = 0 To Me.gvdata.RowCount - 2
_Amt += Me.gvdata.Rows(i).Cells(2).Value
_Price += Me.gvdata.Rows(i).Cells(3).Value
_Total += Me.gvdata.Rows(i).Cells(4).Value
Next
Me.txtAmt.Text = _Amt ' จำนวนต้นไม้
Me.txtPrice.Text = _Price 'เงินทั้งหมด
Me.txtTotal.Text = _Total 'ยอดสุทธิ
End Sub