เพิ่มข้อมูลใน DataGrid แล้ว Insert ลง DB อยากให้ได้ค่าออกมาเป็น ลำดับที่1
j = (dgvSalesOrder.Rows.Count)
For i = 0 To j - 1
sb.Remove(0, sb.Length())
sb.Append("INSERT INTO SalesOrderDetails(Number,Charector_Format,Details,Price,Amount,POPR_ID)")
sb.Append(" VALUES (@Number,@Charector_Format,@Details,@Price,@Amount,@POPR_ID)")
Dim sqlSalesOrderDetails As String
sqlSalesOrderDetails = sb.ToString()
'com = New SqlCommand()
With com
.CommandText = sqlSalesOrderDetails
.CommandType = CommandType.Text
.Connection = Conn
'.Transaction = tr
.Parameters.Clear()
.Parameters.Add("@Number", SqlDbType.Int).Value = Convert.ToInt32(dgvSalesOrder.Rows(i).Cells(0).Value) 'ลำดับให้เริ่มจาก1
.Parameters.Add("@Charector_Format", SqlDbType.NVarChar).Value = Convert.ToString(dgvSalesOrder.Rows(i).Cells(1).Value)
.Parameters.Add("@Details", SqlDbType.Text).Value = Convert.ToString(dgvSalesOrder.Rows(i).Cells(2).Value)
.Parameters.Add("@Price", SqlDbType.Int).Value = Convert.ToInt32(dgvSalesOrder.Rows(i).Cells(3).Value)
.Parameters.Add("@Amount", SqlDbType.Int).Value = Convert.ToInt32(dgvSalesOrder.Rows(i).Cells(4).Value)
.Parameters.Add("@POPR_ID", SqlDbType.NVarChar).Value = txtPOPR_ID.Text.Trim()
.ExecuteNonQuery()
End With