Bellow is the Button Click code which i was trying. Getting error:
The variable name '@srno' has already been declared. variable names must be unique within a query batch or stored procedure.
Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
If con.State = ConnectionState.Open Then
con.Close()
End If
'''+++++++++++++++++++++++++++
Dim i As Integer
Dim rs1 As String
'''++++++++++++++++++++++++++++++++
'================================================================================================================================
Try
For i = 0 To DataGridView1.Rows.Count - 1
rs1 = "INSERT INTO tblProductsve(srno,ItemCode, ProDes, Price,Qty,amt,subtot) VALUES(@srno,@ItemCode, @ProDes, @Price,@Qty,@amt,@subtot)"
Dim cmd As New SqlClient.SqlCommand(rs1, con)
cmd.Parameters.AddWithValue("srno", DataGridView1.Rows(i).Cells(0).Value)
cmd.Parameters.AddWithValue("ItemCode", DataGridView1.Rows(i).Cells(1).Value)
cmd.Parameters.AddWithValue("ProDes", DataGridView1.Rows(i).Cells(2).Value)
cmd.Parameters.AddWithValue("Price", DataGridView1.Rows(i).Cells(3).Value)
cmd.Parameters.AddWithValue("Qty", DataGridView1.Rows(i).Cells(4).Value)
cmd.Parameters.AddWithValue("amt", DataGridView1.Rows(i).Cells(5).Value)
cmd.Parameters.AddWithValue("subtot", TextBox1.Text)
con.Open()
cmd.ExecuteNonQuery()
con.Close()
Next
MessageBox.Show("Save Successully ")
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub