SHARE
TWEET

Menampilkan Data Dari MS Excel ke DataGridView VB .NET

stevennathaniel Feb 16th, 2016 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Imports System.Data.OleDb
  2.  
  3. Imports System.Data
  4.  
  5.  
  6. Public Class Form7
  7.  
  8.     Dim oledbKoneksi As OleDbConnection = New OleDbConnection
  9.  
  10.     Dim oledbPerintah As OleDbCommand = New OleDbCommand
  11.  
  12.     Dim lokasiFile As String = "D:\fileExcel\"
  13.  
  14.     Dim namaFile As String = "LatihanOLEDB2.xlsx"
  15.  
  16.     Dim stringKoneksi As String = "Provider=Microsoft.ACE.OLEDB.12.0;" & "Data Source=" & lokasiFile & namaFile & ";" & "Extended Properties=""Excel 12.0 Xml;HDR=YES;"""
  17.  
  18.     Dim adapter As New OleDbDataAdapter
  19.  
  20.     Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
  21.  
  22.         oledbKoneksi.ConnectionString = stringKoneksi
  23.  
  24.         oledbKoneksi.Open()
  25.  
  26.         oledbPerintah.Connection = oledbKoneksi
  27.  
  28.         oledbPerintah.CommandText = "SELECT * FROM [DataKaryawan$]"
  29.  
  30.         adapter.SelectCommand = oledbPerintah
  31.  
  32.         Dim ds As DataSet
  33.  
  34.         ds = New DataSet
  35.  
  36.         'Tampilkan
  37.  
  38.         adapter.Fill(ds)
  39.  
  40.         DataGridView1.DataSource = ds.Tables(0)
  41.  
  42.         MsgBox("Done!")
  43.  
  44.     End Sub
  45. End Class
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top