คำตอบที่ได้รับเลือกจากเจ้าของกระทู้
ความคิดเห็นที่ 3
'ส่วนบันทึกข้อมูล--------------------------------------------------------------------------------------------------------------
Private Sub ButtonSAve_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonSAve.Click
Dim i As Integer = 0 ' ก็ฟิกซ์ รายการนี้เป็น 0 หรือ ลิสต์มาแค่รายการเดียวนี้...ต้องวน For i = 0 to ... Next ครับ
Ds = New DataSet
Da = New SqlDataAdapter("INSERT INTO Sale( Barcode,FirstName,ProductID, ProductName, Quantity, Price) VALUES ('" & lsview.Items(i).SubItems(0).Text & "', '" & lsview.Items(i).SubItems(1).Text & "', '" & lsview.Items(i).SubItems(2).Text & "', '" & lsview.Items(i).SubItems(3).Text & "', '" & lsview.Items(i).SubItems(4).Text & "', '" & lsview.Items(i).SubItems(5).Text & "' ) ", Sqlcon)
Da.Fill(Ds, "Sale")
Dim a As Integer = 0
a = lsview.Items(i).SubItems(4).Text
Da = New SqlDataAdapter("UPDATE Product SET Quantity = Quantity - " & a & " Where ProductID = '" & lsview.Items(i).SubItems(2).Text & "' ", Sqlcon)
Da.Fill(Ds, "Product")
lsview.Items.Clear()
End Sub
Private Sub ButtonSAve_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonSAve.Click
Dim i As Integer = 0 ' ก็ฟิกซ์ รายการนี้เป็น 0 หรือ ลิสต์มาแค่รายการเดียวนี้...ต้องวน For i = 0 to ... Next ครับ
Ds = New DataSet
Da = New SqlDataAdapter("INSERT INTO Sale( Barcode,FirstName,ProductID, ProductName, Quantity, Price) VALUES ('" & lsview.Items(i).SubItems(0).Text & "', '" & lsview.Items(i).SubItems(1).Text & "', '" & lsview.Items(i).SubItems(2).Text & "', '" & lsview.Items(i).SubItems(3).Text & "', '" & lsview.Items(i).SubItems(4).Text & "', '" & lsview.Items(i).SubItems(5).Text & "' ) ", Sqlcon)
Da.Fill(Ds, "Sale")
Dim a As Integer = 0
a = lsview.Items(i).SubItems(4).Text
Da = New SqlDataAdapter("UPDATE Product SET Quantity = Quantity - " & a & " Where ProductID = '" & lsview.Items(i).SubItems(2).Text & "' ", Sqlcon)
Da.Fill(Ds, "Product")
lsview.Items.Clear()
End Sub
แสดงความคิดเห็น
โค้ด VB จะขายสินค้าหลายอย่าง จากตาราง ListView ทำยังไงคับ มันตัดสินค้าแค่อย่างเดียวคับ
Private Sub ButtonSAve_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonSAve.Click
Dim i As Integer = 0
Ds = New DataSet
Da = New SqlDataAdapter("INSERT INTO Sale( Barcode,FirstName,ProductID, ProductName, Quantity, Price) VALUES ('" & lsview.Items(i).SubItems(0).Text & "', '" & lsview.Items(i).SubItems(1).Text & "', '" & lsview.Items(i).SubItems(2).Text & "', '" & lsview.Items(i).SubItems(3).Text & "', '" & lsview.Items(i).SubItems(4).Text & "', '" & lsview.Items(i).SubItems(5).Text & "' ) ", Sqlcon)
Da.Fill(Ds, "Sale")
Dim a As Integer = 0
a = lsview.Items(i).SubItems(4).Text
Da = New SqlDataAdapter("UPDATE Product SET Quantity = Quantity - " & a & " Where ProductID = '" & lsview.Items(i).SubItems(2).Text & "' ", Sqlcon)
Da.Fill(Ds, "Product")
lsview.Items.Clear()
End Sub