Export Excel data to Datagrid

I was playing around excel and searching for some code which help me to export excel data to Datagrid.

Here is the code. 

Dim strCon As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Suresh\Test.xls;Extended Properties=Excel 8.0;"

Dim objConn As New System.Data.OleDb.OleDbConnection(strCon)

Dim daSuresh As New OleDbDataAdapter("Select * From [Suresh$]", strCon)

objConn.Open()

Dim dsSuresh As New DataSet

Dim dvSuresh As New DataView

daSuresh.Fill(dsSuresh, "Sheet1")

dvSuresh = New DataView(dsSuresh.Tables("Sheet1"))

dvSuresh.Sort = "name"

DataGrid1.DataSource = dsSuresh

DataGrid1.DataMember = dsSuresh.Tables("Sheet1").ToString

DataGrid1.DataBind()

objConn.Close()

Suresh Behera

10 Comments

Comments have been disabled for this content.