KERJA IT - COMPUTER

Markas Rabbani Surabaya Jl.Pucang Anom Timur No. 14 Surabaya Telp. 08123015071 Email : Markas_rabbani_sby@yahoo.co.id

  • RSS
  • Google +
  • Facebook

Popular Posts

IDHOSTINGER memang OK
Radio - TV OnLine
Asyiiikk Bro

VB 2010 - MYSQL

Translate Google

Popular Posts

Markas Rabbani Surabaya

HOSTINGER

Web Hosting

KOMINITAS VFP

IP ADDRESS INFO

IP

Total Tayangan Halaman

HOSTINGER

Web Hosting

Prof DR KH Said Aqil Sirodj - Ketua PB NU

Gus Mus - Prof DR KH Said Aqil Sirodj - Alm Gus Dur

HOSTINGER Web Gratis Tanpa Iklan

Gak Percaya Buktikan

Griya Asy-Syifa

Jl Suromulang Timur II/18 Perum Citra Surodinawan Estate Kota Mojokerto Contac : 081231821800, 08814353000, 085746201881 Pin BB : 24D0B84C e-mail : ariesmojokerto@gmail.com

HOSTINGER Gratis tanpa Iklan

Web Hosting GRATIS dI Indonesia Tanpa Iklan

WaliSongo

Babat alas Tanah Jawa - Pengikut Nabi Muhammad saw - NU

Senin, 14 Juli 2014

IMPORT EXEL KE DATAGRIDVIEW - VB2010

Lihat sebelum di Import


Data Exel nya :



Klik Import  :




Pilih dan Klik Open  , Ini Hasilnya :


Koding yang saya gunakan : 

 Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
        Try
            Dim fBrowse As New OpenFileDialog
            With fBrowse
                .Filter = "Excel files(*.xls)|*.xls|All files (*.*)|*.*"
                .FilterIndex = 1
                .Title = "Import data from Excel file"
            End With
            If fBrowse.ShowDialog() = Windows.Forms.DialogResult.OK Then
                Dim fname As String
                fname = fBrowse.FileName
                Dim ConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
                    "Data Source= " & fname & ";" & " Extended Properties= ""Excel 8.0;"""
                Dim MyConnection As New System.Data.OleDb.OleDbConnection(ConnectionString)
                '  Connection.Open()

                '    Dim MyConnection As System.Data.OleDb.OleDbConnection
                Dim DtSet As System.Data.DataSet
                Dim MyCommand As System.Data.OleDb.OleDbDataAdapter
                ' MyConnection = New System.Data.OleDb.OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;Data Source='d:\xel\test123.xls';Extended Properties=Excel 8.0;")
                MyCommand = New System.Data.OleDb.OleDbDataAdapter("select * from [Sheet1$]", MyConnection)
                MyCommand.TableMappings.Add("Table", "Net-informations.com")
                DtSet = New System.Data.DataSet
                MyCommand.Fill(DtSet)
                dgvoc.DataSource = DtSet.Tables(0)
                MyConnection.Close()
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

atau :

Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click

 
        Dim MyConnection As System.Data.OleDb.OleDbConnection
        Dim DtSet As System.Data.DataSet
        Dim MyCommand As System.Data.OleDb.OleDbDataAdapter
        MyConnection = New System.Data.OleDb.OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;Data Source='d:\xel\test123.xls';Extended Properties=Excel 8.0;")
        MyCommand = New System.Data.OleDb.OleDbDataAdapter("select * from [Sheet1$]", MyConnection)
        MyCommand.TableMappings.Add("Table", "Net-informations.com")
        DtSet = New System.Data.DataSet
        MyCommand.Fill(DtSet)
        dgvoc.DataSource = DtSet.Tables(0)
        MyConnection.Close()

    End Sub

Selamat Ber Otak - Atik

1 komentar:

  1. mas, dah saya coba tp kok eror ada pesan gini pas import dah pilih file excelnya "[Sheet1$] is not invalid name"

    mohon pencerahannya mas..
    thanks

    BalasHapus