kasimacsys
Member
- Joined
- Jul 8, 2009
- Messages
- 10
- Programming Experience
- 1-3
Public Function ImportExcel2DataTable() As DataTable
Dim MyConnection As System.Data.OleDb.OleDbConnection = New System.Data.OleDb.OleDbConnection
Dim DtTable As New DataTable
Dim strShetname As String
Dim DtSet As System.Data.DataSet
Dim MyCommand As System.Data.OleDb.OleDbDataAdapter
Dim PrmPathExcelFile As String = System.IO.Directory.GetCurrentDirectory
MyConnection = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; " & _
"Data Source=D:\Book1.xls; " & "Extended Properties=""Excel 12.0 Xml;HDR=YES""")
Dim oApp As New Excel.Application
Dim oBooks As Excel.Workbooks = oApp.Workbooks
Dim oBook As Excel.Workbook = oBooks.Add("D:\Book1.xls")
Dim oSheet As Excel.Worksheet = oApp.ActiveSheet
strShetname = oSheet.Name
MyCommand = New System.Data.OleDb.OleDbDataAdapter("select * from [" & strShetname & "$]", MyConnection)
MyCommand.TableMappings.Add("Table", "Fusion")
DtSet = New System.Data.DataSet
MyCommand.Fill(DtSet)
MyConnection.Close()
DtTable = DtSet.Tables(0)
Dim AddaRow As DataRow = DtTable.NewRow
DtTable.Rows.InsertAt(AddaRow, 0)
ImportExcel2DataTable = DtTable
End Function
In the above i receive error could not find installable ISAM in "MyCommand.Fill(DtSet)" line
Dim MyConnection As System.Data.OleDb.OleDbConnection = New System.Data.OleDb.OleDbConnection
Dim DtTable As New DataTable
Dim strShetname As String
Dim DtSet As System.Data.DataSet
Dim MyCommand As System.Data.OleDb.OleDbDataAdapter
Dim PrmPathExcelFile As String = System.IO.Directory.GetCurrentDirectory
MyConnection = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; " & _
"Data Source=D:\Book1.xls; " & "Extended Properties=""Excel 12.0 Xml;HDR=YES""")
Dim oApp As New Excel.Application
Dim oBooks As Excel.Workbooks = oApp.Workbooks
Dim oBook As Excel.Workbook = oBooks.Add("D:\Book1.xls")
Dim oSheet As Excel.Worksheet = oApp.ActiveSheet
strShetname = oSheet.Name
MyCommand = New System.Data.OleDb.OleDbDataAdapter("select * from [" & strShetname & "$]", MyConnection)
MyCommand.TableMappings.Add("Table", "Fusion")
DtSet = New System.Data.DataSet
MyCommand.Fill(DtSet)
MyConnection.Close()
DtTable = DtSet.Tables(0)
Dim AddaRow As DataRow = DtTable.NewRow
DtTable.Rows.InsertAt(AddaRow, 0)
ImportExcel2DataTable = DtTable
End Function
In the above i receive error could not find installable ISAM in "MyCommand.Fill(DtSet)" line