Private Sub AddToCheck()
Dim strsql As String
strsql = "insert into GoodsCheck (goodsID,room,sumAmount) values (@goodsID,@room,@sumAmount)"
conn.Open()
cm = New SqlCommand(strsql, conn)
For i As Integer = 0 To DataGridView3.Rows.Count - 1
With cm
.Parameters.Clear()
.Parameters.AddWithValue("@goodsID", SqlDbType.NVarChar).Value = CStr(DataGridView3.Rows(i).Cells(0).Value)
.Parameters.AddWithValue("@room", SqlDbType.NVarChar).Value = CStr(DataGridView3.Rows(i).Cells(1).Value)
.Parameters.AddWithValue("@sumAmount", SqlDbType.Int).Value = CStr(DataGridView3.Rows(i).Cells(2).Value)
.ExecuteNonQuery()
End With
Next
conn.Close()
ds = UpdateSum()
With DataGridView3
.DataSource = ds.Tables("GoodsCheck")
.AutoGenerateColumns = False
End With
End Sub 'Sub เพิ่มข้อมูลลงตาราง GoodsCheck
Dim strsql As String
strsql = "insert into GoodsCheck (goodsID,room,sumAmount) values (@goodsID,@room,@sumAmount)"
conn.Open()
cm = New SqlCommand(strsql, conn)
For i As Integer = 0 To DataGridView3.Rows.Count - 1
With cm
.Parameters.Add(New SqlParameter("@goodsID", SqlDbType.VarChar, (DataGridView3.Rows(i).Cells(0).Value)))
.Parameters.Add(New SqlParameter("@room", SqlDbType.VarChar, (DataGridView3.Rows(i).Cells(1).Value)))
.Parameters.Add(New SqlParameter("@sumAmount", SqlDbType.Int, (DataGridView3.Rows(i).Cells(2).Value)))
.ExecuteNonQuery()
.Parameters.Clear()
End With
Next
conn.Close()
Private Sub BtnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSave.Click
strsql = "insert into OrderDetail(OrderID,ProductID,NumberOrder,UnitID,Weight,UnitWeightID,Driver,RegisDriver) values(@OrderId,@ProductID,@ProductName,@NumberOrder,@UnitID,@Weight,@UnitWeightID,@Driver,@RegisDriver)"
objCmd = New System.Data.SqlClient.SqlCommand(strsql, DbConn)
For i As Integer = 0 To DataGridOrder.RowCount - 1
If Not DataGridOrder.Rows(i).IsNewRow Then
With objCmd
.Parameters.Add(New SqlParameter("@OrderId", orderID.Text))
.Parameters.Add(New SqlParameter("@ProductID", DataGridOrder.Rows(i).Cells(0).Value))
.Parameters.Add(New SqlParameter("@NumberOrder", DataGridOrder.Rows(i).Cells(1).Value))
.Parameters.Add(New SqlParameter("@UnitId", DataGridOrder.Rows(i).Cells(2).Value))
.Parameters.Add(New SqlParameter("@Weight", DataGridOrder.Rows(i).Cells(3).Value))
.Parameters.Add(New SqlParameter("@UnitWeightID", DataGridOrder.Rows(i).Cells(4).Value))
.Parameters.Add(New SqlParameter("@Driver", Driver.Text))
.Parameters.Add(New SqlParameter("@RegisDriver", RegisDriver.Text))
End With
objCmd.ExecuteNonQuery()
objCmd.Parameters.Clear()
End If
Next
MessageBox.Show("บันทึกข้อมูลแล้ว")
DbConn.Close()
End Sub