 |
|
คือถ้าผมต้องการที่จะดึงข้อมูลจากฐานข้อมูลมาคิดค่า คำนวนสินค้า ต้องใส่โค้ดอะไรบ้างครับ |
|
 |
|
|
 |
 |
|
ตอนที่คุณ ดึง ข้อมูลจากฐานข้อมูล คุณก็คำนวณ เลย แล้วเอามาแสดงใน Gridview
เช่น
Code (VB.NET)
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
ใช่อย่างนี้หรือเปล่าไม่แน่ใจ (ไม่ค่อยเข้าใจ คำถาม)
|
 |
 |
 |
 |
Date :
2012-04-02 16:32:45 |
By :
Thep |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองดูแบบฟอล์มน่ะคับ
เหมือนกับว่าเมื่อเราเลือกต้นไม้ ให้โชว์ใน dataGridview
แล้วใส่โค้ดคิดคำนวนราคาตามแบบฟอล์มครับ
|
 |
 |
 |
 |
Date :
2012-04-02 17:07:50 |
By :
tomza |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
หมายความว่า Click เลือก ต้นไม้ 1 ต้น ก็ไปดึงข้อมูลจาก Database มา คำนวณ ราคา และ ยอดรวม แล้ว add เพิ่มเข้าไปใน Gridview
พอ กด ต้นที่ 2 ก็ add เพิ่มเข้าไปใน Gridview อย่างนี้ไปเรื่อยๆ ใช่หรือเปล่า?
|
 |
 |
 |
 |
Date :
2012-04-03 08:23:14 |
By :
Thep |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
กำลังเรียน เหมือนกัน
|
ประวัติการแก้ไข 2012-04-05 16:27:43
 |
 |
 |
 |
Date :
2012-04-03 09:51:02 |
By :
saberr40 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ใช่ครับบบ 
|
 |
 |
 |
 |
Date :
2012-04-03 09:56:46 |
By :
tomza |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
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
ลองดูครับ
|
 |
 |
 |
 |
Date :
2012-04-03 11:54:26 |
By :
Thep |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ต้องเอาโค้ดไปวางตรงไหนครับบ
|
 |
 |
 |
 |
Date :
2012-04-03 16:57:28 |
By :
tomza |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|

ต่อ

|
 |
 |
 |
 |
Date :
2012-04-04 13:44:20 |
By :
tomza |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|