Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Sub excelAsql()
- Dim myFileDialog As New OpenFileDialog()
- Dim xSheet As String = ""
- With myFileDialog
- .Filter = "Archivos de Excel |*.xlsx"
- .Title = "Abrir archivo excel"
- .ShowDialog()
- End With
- If myFileDialog.FileName.ToString <> "" Then
- Try
- Dim ExcelFile As String = myFileDialog.FileName.ToString
- xSheet = InputBox("Nombre de la Hoja", "")
- conn = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;" & "data source=" & ExcelFile & "; " & "Extended Properties='Excel 12.0;HDR=Yes'")
- conn.Open()
- da = New OleDbDataAdapter("SELECT * FROM [" & xSheet & "$]", conn)
- Dim dt As New DataTable
- da.Fill(dt)
- frmLista.DataGridView1.DataSource = dt
- Catch ex As Exception
- MsgBox(ex.Message)
- End Try
- End If
- End Sub
Add Comment
Please, Sign In to add comment