我有TableA和TableB,TableA包含数据@ 2,@ 3,@ 4,@ 8,TableB是我要插入的表。如何从TableA中选择数据并插入TableB?目前我需要首先从TableA检索数据并声明变量来存储数据然后只能插入到TableB中。
Private Sub btn_save_Click(sender As Object, e As EventArgs) Handles btn_save.Click
Select Case MessageBox.Show($"Confirm to update?", "Confirm?", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
Case MsgBoxResult.Yes
For Each dgvrow As DataGridViewRow In dgv_stock.Rows
With dgvrow
If .Cells("Quantity").Value > 0 Then
Dim str_type As String = .Cells("Type").Value
Dim int_id As Integer = .Cells("stkitm_id").Value
Dim int_qty As Integer = .Cells("Quantity").Value
Dim str_remark As String = .Cells("Remark").Value
Model_Update(str_type, int_id, int_qty)
Model_Insert(str_type, int_id, int_qty, str_remark)
End If
End With
Next
RefreshDGV()
End Select
End Sub
Private Sub Model_Insert(p_type As String, p_id As Integer, p_qty As Integer, p_remark As String)
Dim query As String = "INSERT INTO stock_history (stkitm_id,stkitm_code,stkitm_name,stkhis_type,stkhis_qty,
stkhis_remark,stkhis_onhand,created_by)
VALUES (@2,@3,@4,@5,@6,@7,@8,@9)"
Using cmd = New MySqlCommand(query, conn)
cmd.Parameters.AddWithValue("@2", )
cmd.Parameters.AddWithValue("@3", )
cmd.Parameters.AddWithValue("@4", )
cmd.Parameters.AddWithValue("@5", p_type)
cmd.Parameters.AddWithValue("@6", p_qty)
cmd.Parameters.AddWithValue("@7", p_remark)
cmd.Parameters.AddWithValue("@8", )
cmd.Parameters.AddWithValue("@9", g_currUser)
cmd.ExecuteNonQuery()
End Using
End Sub