your code is almost correct just add this to your button2_click() event
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
Dim dt As New DataTable
Dim ds As New System.Data.DataSet
ds = DatagridviewToDataset(DataGridView1)
dt = ds.Tables(0)
Add this Function to your program
Public Function DatagridviewToDataset(ByVal dgv As DataGridView) As System.Data.DataSet
Dim ds As New System.Data.DataSet
Try
ds.Tables.Add("Main")
Dim col As System.Data.DataColumn
For Each dgvCol As DataGridViewColumn In dgv.Columns
col = New System.Data.DataColumn(dgvCol.Name)
ds.Tables("Main").Columns.Add(col)
Next
Dim row As System.Data.DataRow
Dim colcount As Integer = dgv.Columns.Count - 1
For i As Integer = 0 To dgv.Rows.Count - 1
row = ds.Tables("Main").Rows.Add
For Each column As DataGridViewColumn In dgv.Columns
row.Item(column.Index) = dgv.Rows.Item(i).Cells(column.Index).Value
Next
Next
Return ds
Catch ex As Exception
MessageBox.Show("Error Converting from DataGridView" & ex.InnerException.ToString, _
"Error Converting from DataGridView", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return Nothing
End Try
End Function