title: How to transfer the excel file to database access using vb.net?
body: <p>i have 3 button that is use to transfer the data from excell file to acces database., this is the interface of the windows form</p>
  
  <p><a href="https://i.stack.imgur.com/xQGzM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xQGzM.png" alt="enter image description here"></a></p>
  
  <p>the <strong>first</strong> button is use to open dialog openfile to select the file exel </p>
  
  <p>the <strong>second</strong> is use to open the excel file and store to the datatable.</p>
  
  <p>and the <strong>third</strong> button is use to transfer the excel data to access.</p>
  
  <p>this is the code of </p>
  
  <p><strong>first button</strong></p>
  
  <pre><code>Private Sub cmdGetExcel_Click(sender As System.Object, e As System.EventArgs) Handles cmdGetExcel.Click
          Try
              Dim fd As OpenFileDialog = New OpenFileDialog()
              Dim strFileName As String
  
              fd.Title = "Open File Dialog"
              fd.InitialDirectory = "C:\"
              fd.Filter = "Excel files(*.xls)|*.xls"
              fd.FilterIndex = 2
              fd.RestoreDirectory = True
  
  
              If fd.ShowDialog() = DialogResult.OK Then
                  strFileName = fd.FileName
                  path = fd.FileName
                  Text1.Text = path
  
              Else
  
  
  
              End If
  
          Catch ex As Exception
              MessageBox.Show(ex.Message)
          End Try
  
      End Sub
  </code></pre>
  
  <p>this is a code of
  <strong>second button</strong></p>
  
  <pre><code> Private Sub OpenDatabase_Click(sender As System.Object, e As System.EventArgs) Handles OpenDatabase.Click
          Try
  
              Dim connectexcelstring As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source='" &amp; Text1.Text &amp; "';" &amp; _
                   "Extended Properties=""Excel 8.0;HDR=yes"""
              Dim con As OleDbConnection = New OleDbConnection(connectexcelstring)
  
              con.Open()
  
              Dim query As String = "Select * from [Sheet1$]"
  
              Dim excelcmd As OleDbCommand = New OleDbCommand(query, con)
  
  
              dt.Load(excelcmd.ExecuteReader())
  
              Dim rowData As String = ""
              Dim i = 0
  
              For Each row As DataRow In dt.Rows
                  For Each column As DataColumn In dt.Columns()
                      rowData = rowData &amp; column.ColumnName &amp; "=" &amp; row(column) &amp; " "
                  Next
                  rowData = rowData &amp; vbNewLine &amp; vbNewLine
              Next
  
  
  
              MessageBox.Show(rowData)
  
              MsgBox("Destination Database has been open")
  
          Catch ex As Exception
  
              MessageBox.Show(ex.Message)
          End Try
      End Sub
  </code></pre>
  
  <p>this is the <strong>third</strong> button , (the transfer button)</p>
  
  <pre><code> Private Sub TransferExcelFile2Database_Click(sender As System.Object, e As System.EventArgs) Handles TransferExcelFile2Database.Click
  
      End Sub
  </code></pre>
  
  <p>im not have idea how to transfer the excel file in transfer button ,,</p>
  
  <p>any idea?</p>