Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System.Data.OleDb
- Imports System.Data
- Public Class Form7
- Dim oledbKoneksi As OleDbConnection = New OleDbConnection
- Dim oledbPerintah As OleDbCommand = New OleDbCommand
- Dim lokasiFile As String = "D:\fileExcel\"
- Dim namaFile As String = "LatihanOLEDB2.xlsx"
- Dim stringKoneksi As String = "Provider=Microsoft.ACE.OLEDB.12.0;" & "Data Source=" & lokasiFile & namaFile & ";" & "Extended Properties=""Excel 12.0 Xml;HDR=YES;"""
- Dim adapter As New OleDbDataAdapter
- Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
- oledbKoneksi.ConnectionString = stringKoneksi
- oledbKoneksi.Open()
- oledbPerintah.Connection = oledbKoneksi
- oledbPerintah.CommandText = "SELECT * FROM [DataKaryawan$]"
- adapter.SelectCommand = oledbPerintah
- Dim ds As DataSet
- ds = New DataSet
- 'Tampilkan
- adapter.Fill(ds)
- DataGridView1.DataSource = ds.Tables(0)
- MsgBox("Done!")
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement