Private Sub btnconfirm_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnconfirm.Click 'ปุ่มบันทึกข้อมูล
Dim sb As New StringBuilder
Dim tr As OleDbTransaction
Dim NumRows As Integer
tr = accon.BeginTransaction
Try
sb.Remove(0, sb.Length)
sb.Append("insert into Sale_Detail (Sale_id,Pro_id,Pro_SalePrice,Pro_amount) ")
sb.Append("values (@Sale_id,@Pro_id,@Pro_SalePrice,@Pro_amount)")
Dim sqladd As String
sqladd = sb.ToString
For i As Integer = 0 To DataGridView1.RowCount - 1
If Not DataGridView1.Rows(i).IsNewRow Then
With cmd
cmd.CommandText = sqladd
cmd.CommandType = CommandType.Text
cmd.Connection = accon
cmd.Parameters.Clear()
cmd.Transaction = tr
cmd.Parameters.Add("Sale_id", OleDbType.VarChar).Value = txt_sale_id.Text.Trim
cmd.Parameters.Add("Pro_id", OleDbType.VarChar).Value = DataGridView1.Rows(i).Cells(1).Value
cmd.Parameters.Add("Pro_SalePrice", OleDbType.Integer).Value = DataGridView1.Rows(i).Cells(4).Value
cmd.Parameters.Add("Pro_amount", OleDbType.Integer).Value = DataGridView1.Rows(i).Cells(3).Value
cmd.ExecuteNonQuery()
End With
End If
Next
ติดตรงส่วนนี้ค่ะ บันทึกข้อมูลลงตาราง Sale ไม่ได้ค่ะ >>>>>>>>>>>sql = String.Format("Insert into Sale(Sale_id, Sale_date)" & _ " Values('{0}','{1}')", txt_sale_id.Text, DateTimePicker1.Text)
cmd_excuteNonquery()
tr.Commit()
MsgBox("บันทึกข้อมูลเรียบร้อยค่ะ")
Catch ex As Exception
MsgBox(ex.Message)
tr.Rollback()
End Try