Dim i As Integer = ListView_sale.Items.Count - 1
For j As Integer = 0 To i
Dim product_id As String = ListView_sale.Items(j).SubItems(1).Text
Dim product_amount As Integer = ListView_sale.Items(j).SubItems(4).Text
Dim product_total As Double = ListView_sale.Items(j).SubItems(5).Text
sql = "insert into sale_detail(sale_id,product_id,sale_detailProduct_amount,sale_detailProduct_total) values (@a1,@a2,@a3,@a4)"
cmd = New SqlClient.SqlCommand(sql, cn)
cmd.Parameters.Clear()
cmd.Parameters.AddWithValue("a1", sale_max)
cmd.Parameters.AddWithValue("a2", product_id)
cmd.Parameters.AddWithValue("a3", product_amount)
cmd.Parameters.AddWithValue("a4", product_total)
Next
If cmd.ExecuteNonQuery = 0 Then
msg_error("ไม่สามารถบันทึกข้อมูลได้")
Return
Else
msg_ok("บันทึกข้อมูลสำเร็จ")
End If
Tag : .NET, Ms SQL Server 2012, Win (Windows App), VB.NET, Windows