.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month

Home >> Code Snippets >> Windows Form Controls >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Retrieving Excel Data To dataGridview

Posted By:satyapriyanayak       Posted Date: March 11, 2013    Points: 40    Category: Windows Form Controls    URL: http://www.dotnetspark.com  

Retrieving Excel Data To dataGridview

Here we can retrieve Excel Data To dataGridview .It only support Extended Properties Excel version 8.0(Microsoft 2000 version).



Module1.vb code

Imports System.Data.OleDb

Module Module1

    Public con As OleDbConnection

    Sub pintu(ByVal s As String)

        con = New OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0; " & _

                                        "data source='" & s & " '; " & "Extended Properties=Excel 8.0;")

    End Sub

    Public com As OleDbCommand

    Public ds As DataSet

    Public oledbda As OleDbDataAdapter

    Public dt As DataTable

    Public str As String

End Module

Form1.vb code

Imports System.Data.OleDb

Public Class Form1

    Private Sub btnbrowse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnbrowse.Click

        Dim openfiledialog1 As New OpenFileDialog


        openfiledialog1.Filter = "allfiles|*.xls"

        TextBox1.Text = openfiledialog1.FileName

    End Sub

    Private Sub btndisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btndisplay.Click




            str = "select * from [sheet1$]"

            com = New OleDbCommand(str, con)

            ds = New DataSet

            oledbda = New OleDbDataAdapter(com)

            oledbda.Fill(ds, "[sheet1$]")


            DataGridView1.DataSource = ds

            DataGridView1.DataMember = "[sheet1$]"

        Catch ex As Exception


        End Try

    End Sub

End Class


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend