Insert datagrid values into SQL Server table
<p>I'm trying to insert some runtime generated datagridview values into a SQL Server table. </p>

<p>Here is my code:</p>

<pre><code>Private Sub btnTrimitebon_Click(sender As Object, e As EventArgs) Handles btnTrimitebon.Click
    functii.adaugabonmagazie()
    Dim dvgPieseCumparate As New DataGridView
    Dim command As New Data.SqlClient.SqlCommand
    Dim con As New Data.SqlClient.SqlConnection
    Dim dt As DataTable = functii.piesecumparate(txtFpo.Text)
    dvgPieseCumparate.AutoGenerateColumns = True
    dvgPieseCumparate.AllowUserToAddRows = False
    dvgPieseCumparate.AllowUserToDeleteRows = False
    dvgPieseCumparate.AllowUserToOrderColumns = False
    dvgPieseCumparate.AutoSizeColumnsMode =
        DataGridViewAutoSizeColumnsMode.AllCells
    dvgPieseCumparate.DataSource = dt
    dvgPieseCumparate.Refresh()
    Try
        con.ConnectionString = "Data Source=SVNAV;Initial Catalog=NAV_Vermorel_Live;User ID=sa;Password=1234"
        command.CommandText = "INSERT INTO [dbo].[SC Vermorel SRL$MagLines]
          ([RPO]
          ,[FPO]
          ,[Articol]
          ,[Description]
          ,[QtyperPiesa]
          ,[QtyTotal]
          ,[Indice])
    VALUES
          (@RPO
          ,@FPO
          ,@Articol
          ,@Description,
          ,@QtyperPiesa
          ,@QtyTotal
          ,@Indice)"
        command.Parameters.Add("@RPO", SqlDbType.VarChar)
        command.Parameters.Add("@FPO", SqlDbType.VarChar)
        command.Parameters.Add("@Articol", SqlDbType.VarChar)
        command.Parameters.Add("@Description", SqlDbType.VarChar)
        command.Parameters.Add("@QtyperPiesa", SqlDbType.Int)
        command.Parameters.Add("@QtyTotal", SqlDbType.Int)
        command.Parameters.Add("@Indice", SqlDbType.VarChar)
        con.Open()
        command.Connection = con
        For i As Integer = 0 To dvgPieseCumparate.Rows.Count - 1
            command.Parameters(0).Value = dvgPieseCumparate.Rows(i).Cells(0).Value
            command.Parameters(1).Value = dvgPieseCumparate.Rows(i).Cells(1).Value
            command.Parameters(2).Value = dvgPieseCumparate.Rows(i).Cells(2).Value
            command.Parameters(3).Value = dvgPieseCumparate.Rows(i).Cells(3).Value
            command.Parameters(4).Value = dvgPieseCumparate.Rows(i).Cells(4).Value
            command.Parameters(5).Value = dvgPieseCumparate.Rows(i).Cells(5).Value
            command.Parameters(6).Value = dvgPieseCumparate.Rows(i).Cells(6).Value
            command.ExecuteNonQuery()
        Next
    Catch ex As Exception
        Console.WriteLine(ex.Message)
    Finally
        If con IsNot Nothing Then
            If con.State = ConnectionState.Open Then
                con.Close()
            End If
            con.Dispose()
        End If
    End Try
End Sub
</code></pre>

<p>Also the table definition from SSMS:</p>

<p><a href="https://i.stack.imgur.com/GjANp.jpg" rel="nofollow"><img src="https://i.stack.imgur.com/GjANp.jpg" alt="table definition"></a></p>

<p>If I generate the dgv and put it and display it on a form its ok, but when I try to add its values in the sql table, no error, but no values added also.</p>

<p><a href="https://i.stack.imgur.com/vYqkh.jpg" rel="nofollow"><img src="https://i.stack.imgur.com/vYqkh.jpg" alt="datagridview"></a></p>

<p>What am I doing wrong?</p>