Excel (.xls) Sheet To DataSet
1. Import NameSpace
Imports System.Data
Imports System.Data.Oledb
2. 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.Jet.OLEDB.4.0;" & _
"Data Source=D:\MyXls\MyExcelDB.xls;" & _
"Extended Properties=""Excel 8.0;"""
''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()
Imports System.Data
Imports System.Data.Oledb
2. 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.Jet.OLEDB.4.0;" & _
"Data Source=D:\MyXls\MyExcelDB.xls;" & _
"Extended Properties=""Excel 8.0;"""
''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()
Comments
Post a Comment