I need to add currently shows datagridview data in another table. If i add the data, database should took the last data in datagridview. Please guys, need your assistance, Guide me.
What I have tried:
Try
con = New SqlConnection(cs)
con.Open()
Dim sqlInsertT2 As String = ""
For i As Integer = 0 To DataGridView1.RowCount - 1
sqlInsertT2 &= " Insert Into Techsp(Jobno,Qty,Jobid,Item,AU,ItemQty,Category,TotalQty) Values ('" & TextBox1.Text & "','" & TextBox4.Text & "','" & TextBox6.Text & "','" & DataGridView1.Rows(i).Cells("Items").Value & "','" & DataGridView1.Rows(i).Cells("A/U").Value & "','" & DataGridView1.Rows(i).Cells("Item Qty").Value & "','" & DataGridView1.Rows(i).Cells("Category").Value & "',@TotalQty);"
cmd = New SqlCommand(sqlInsertT2)
cmd.Connection = con
Dim iresult As Integer
iresult = Val(TextBox4.Text) * Val(DataGridView1.Rows(i).Cells("Item Qty").Value)
cmd.Parameters.AddWithValue("Jobno", TextBox1.Text)
cmd.Parameters.AddWithValue("Qty", TextBox4.Text)
cmd.Parameters.AddWithValue("Jobid", Textbox6.Text)
cmd.Parameters.AddWithValue("Item", DataGridView1.Rows(i).Cells("Items").Value)
cmd.Parameters.AddWithValue("AU", DataGridView1.Rows(i).Cells("A/U").Value)
cmd.Parameters.AddWithValue("ItemQty", DataGridView1.Rows(i).Cells("Item Qty").Value)
cmd.Parameters.AddWithValue("Category", DataGridView1.Rows(i).Cells("Category").Value)
cmd.Parameters.AddWithValue("@TotalQty", iresult)
Next
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
cmd.ExecuteReader()