Sunday, April 27, 2014

Visual Basic .NET Tutorial 53 -How to import excel file to datagridview ...







Public Class Form1


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        
        Try

            Dim MyConnection As System.Data.OleDb.OleDbConnection
            Dim dataSet As System.Data.DataSet
            Dim MyCommand As System.Data.OleDb.OleDbDataAdapter
            Dim path As String = "C:\\Users\\dwishika\\Desktop\\vids\\excel\\Book1.xlsx"

            MyConnection = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=Excel 12.0;")
            MyCommand = New System.Data.OleDb.OleDbDataAdapter("select * from [Sheet1$]", MyConnection)

            dataSet = New System.Data.DataSet
            MyCommand.Fill(dataSet)
            DataGridView1.DataSource = dataSet.Tables(0)

            MyConnection.Close()
        Catch ex As Exception
            MsgBox(ex.Message.ToString)
        End Try

    End Sub
End Class












---------------------------------------

Importing Any Excel Spreadsheet into a DataGridView - C#
VB.NET - Importing Excel File to dataGridView
import Excel File to VB.NET.net DataGridView
Import Excel To DatagridView
Import Data from Excel to DataGridView in VB.NET
import from excel to datagridview
VB.NET DataGridView Loading data from Excel
importing excel file into datagridview  How to get data from excel sheet to datagridview in VB.NET importing RowName and ColumnName from an excelfile posts
Import Excel file to DataGridView‎ VB.NET
Saving DataGrid View to Excel and opening Excel to
How to import data from Excel to Datagrid‎
How to Export Datagridview contents to Excel - VB.NET

9 comments:

  1. thanks for sharing, it helped a lot, but i have another problem. How to choose any excel files in Windows to show in DataGridView in our program?

    ReplyDelete
  2. VISUAL BASIC.NET
    A LINK
    WHERE DOWNLOAD?
    I DON´T SPEACK ENGLIS

    ReplyDelete
  3. Code works great. Awesome dude!!

    ReplyDelete
  4. Hi
    I have one query here. How to update the information loaded into the data-grid and save it into the same excel sheet? Please past the code here.

    ReplyDelete
  5. So Feel like everything works, except when I click my button i get a message that appears and it says "Could not find installable ISAM"...what does this mean and how do I fix it?

    ReplyDelete
    Replies
    1. encountered same error message. i just copied the codes . "Could not find installable ISAM" is gone . but i have this error message "Failure Creating File" :)

      Delete
  6. anyone encountered this error message?
    "Failure Creating File"

    ReplyDelete
  7. hi i want to know how do i use any sheet based on its name which might be variable instead of ("select * from [Sheet1$]")

    ReplyDelete