title: VB.NET Insert DataGridView contents into Database
body: <p><strong>Problem:</strong></p>
  
  <p>I need to dump the contents of my DataGridView into a SQL Server Database Table.  I've got the datagridview loading fine, no problems there.  I'm just not familiar enough with VB.NET to understand how to get that data into a DB table.</p>
  
  <p><strong>Code: (so far)</strong></p>
  
  <pre><code>    Dim connection As New Data.SqlClient.SqlConnection
      Dim dataAdapter As New Data.SqlClient.SqlDataAdapter
      Dim command As New Data.SqlClient.SqlCommand
      Dim dataSet As New Data.DataSet
  
      connection.ConnectionString = "Server= server; Database= DB; integrated security=true"
      command.CommandText = "INSERT INTO &lt;table&gt; (Col1, Col2, Col3, Col4) VALUES (@Name, @Property, @Value, @Date)"
  
      dataAdapter.InsertCommand.Parameters.Add("@ServerName", SqlDbType.VarChar)
      dataAdapter.InsertCommand.Parameters.Add("@Property", SqlDbType.VarChar)
      dataAdapter.InsertCommand.Parameters.Add("@Value", SqlDbType.VarChar)
      dataAdapter.InsertCommand.Parameters.Add("@CaptureDate", SqlDbType.DateTime)
  
      For i As Integer = 0 To DataGridView.Rows.Count - 1
          dataAdapter.InsertCommand.Parameters(0).Value = dgvServerConfig.Rows(i).Cells(0).Value
          dataAdapter.InsertCommand.Parameters(1).Value = dgvServerConfig.Rows(i).Cells(1).Value
          dataAdapter.InsertCommand.Parameters(2).Value = dgvServerConfig.Rows(i).Cells(2).Value
          dataAdapter.InsertCommand.Parameters(3).Value = dgvServerConfig.Rows(i).Cells(3).Value
      Next
  
      connection.Open()
      command.Connection = connection
      dataAdapter.SelectCommand = command
  </code></pre>
  
  <p>What am I missing here?  Nothing is getting inserted into my table.  Any help would be appreciated.  Like I said, I'm not very familiar with VB so take it easy on me.</p>