title: Save Datagrid data to SQL Server database in VB.Net
body: <p>I have a datagrid with data. Column one is a combobox with importers whereas column two is the quantity imported. I want to be able to save this data to the DB irrespective of the user's selection.</p>
  
  <p>Please see my code show below. Can someone help me out?</p>
  
  <pre><code>Dim intReturnValue As Integer = 0
  
  Dim SqlCmd As String = "Update Importer_Balance SET Quantity = Quantity + @Quantity WHERE Importer=@Importer and Product=@product" 
  
  Dim ConnObj As SqlConnection = New SqlConnection(clsGlobals.ConnString)
  Dim CmdObj As SqlCommand = New SqlCommand(SqlCmd, ConnObj)
  
  For i = 0 To Me.dgvImporter.RowCount - 1
          CmdObj.Parameters.AddWithValue("@Importer", Me.dgvImporter.Rows(i).Cells(0).Value)
          CmdObj.Parameters.AddWithValue("@Quantity", Me.dgvImporter.Rows(i).Cells(1).Value)
          CmdObj.Parameters.AddWithValue("@Product", cboProductName.SelectedValue)
  Next
  
  ConnObj.Open()
  
  intReturnValue = CInt(CmdObj.ExecuteNonQuery())
  
  ConnObj.Close()
  
  If intReturnValue &gt; 0 Then
          MsgBox("You have successfully updated the product table product.", MsgBoxStyle.Information, "")
          ClearForm()
  Else
          MsgBox("No Record were inserted", MsgBoxStyle.Exclamation, "")
  End If
  </code></pre>