Guest User

Untitled

a guest
Jan 23rd, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. Sub excelAsql()
  2. Dim myFileDialog As New OpenFileDialog()
  3. Dim xSheet As String = ""
  4. With myFileDialog
  5. .Filter = "Archivos de Excel |*.xlsx"
  6. .Title = "Abrir archivo excel"
  7. .ShowDialog()
  8. End With
  9.  
  10. If myFileDialog.FileName.ToString <> "" Then
  11. Try
  12. Dim ExcelFile As String = myFileDialog.FileName.ToString
  13. xSheet = InputBox("Nombre de la Hoja", "")
  14. conn = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;" & "data source=" & ExcelFile & "; " & "Extended Properties='Excel 12.0;HDR=Yes'")
  15. conn.Open()
  16. da = New OleDbDataAdapter("SELECT * FROM [" & xSheet & "$]", conn)
  17.  
  18. Dim dt As New DataTable
  19. da.Fill(dt)
  20. frmLista.DataGridView1.DataSource = dt
  21. Catch ex As Exception
  22. MsgBox(ex.Message)
  23. End Try
  24. End If
  25. End Sub
Add Comment
Please, Sign In to add comment