title: Import from Excel to datagridview with OLEDB in vb.net
body: <p>I'm using below code to import Excel sheet to datagridview. If there's no pre-defined columns in Datagridview there's no problem but i have pre-defined columns when i'm import the file it creates new columns. How is it possible to prevent this situation.</p>
  
  <pre><code>Public Shared Sub NewMethod2(ByVal dgv As DataGridView)
      Dim filepath As String
      Dim ofd As OpenFileDialog = New OpenFileDialog With {
          .Filter = "Excel Files | *.xlsx",
          .Title = "Import Model Info Sheet"
      }
      Try
          If ofd.ShowDialog() = DialogResult.OK Then
              filepath = Path.GetFullPath(ofd.FileName)
              Globals.ModelInfoSheet = filepath
          End If
          frmMain.Label1.Text = Globals.ModelInfoSheet
          dgv.DataSource = Nothing
          Dim MyConnection As OleDb.OleDbConnection
          Dim MyCommand As OleDb.OleDbDataAdapter
          MyConnection = New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source='" &amp; Globals.ModelInfoSheet &amp; "';Extended Properties=Excel 12.0;")
          MyCommand = New OleDb.OleDbDataAdapter("select * from [Sheet1$]", MyConnection)
          MyCommand.TableMappings.Add("srcTablePa", "setTablePa")
          Dim DtSet As DataTable
          DtSet = New DataTable
          MyCommand.Fill(DtSet)
          dgv.DataSource = DtSet
  
          MyConnection.Close()
  
          MessageBox.Show("File successfully imported")
  
      Catch ex As Exception
          MsgBox(ex.Message)
      End Try
  End Sub
  </code></pre>