Excel (.xlsx) Sheet To DataSet
1. Install Package
Microsoft Access Database Engine 2010 Redistributable
2. Import NameSpace
Imports System.Data
Imports System.Data.Oledb
3. Development
Dim myDataset As New DataSet()
''You can also use the Excel ODBC driver I believe - didn''t try though
Dim strConn As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\Excel.xlsx;Extended Properties=""Excel 12.0 Xml;HDR=YES"";"
''You must use the $ after the object you reference in the spreadsheet (## Table Name is ExcelTest ##)
Dim myData As New OledbDataAdapter("SELECT * FROM [Sheet1$]", strConn)
myData.TableMappings.Add("Table", "ExcelTest")
myData.Fill(myDataset)
DataGrid1.DataSource = myDataset.Tables(0).DefaultView
DataGrid1.DataBind()
Refer :: Connection String
Microsoft Access Database Engine 2010 Redistributable
2. Import NameSpace
Imports System.Data
Imports System.Data.Oledb
3. Development
Dim myDataset As New DataSet()
''You can also use the Excel ODBC driver I believe - didn''t try though
Dim strConn As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\Excel.xlsx;Extended Properties=""Excel 12.0 Xml;HDR=YES"";"
''You must use the $ after the object you reference in the spreadsheet (## Table Name is ExcelTest ##)
Dim myData As New OledbDataAdapter("SELECT * FROM [Sheet1$]", strConn)
myData.TableMappings.Add("Table", "ExcelTest")
myData.Fill(myDataset)
DataGrid1.DataSource = myDataset.Tables(0).DefaultView
DataGrid1.DataBind()
Refer :: Connection String
Comments
Post a Comment