Use Tuple to send Excel Column headers and data row from same function using

Posted by Rajnilari2015 under VB.NET category on | Points: 40 | Views : 1915

Public Function ReadXcel(fileName As String, sheetName As String, tblName As String) As Tuple(Of DataTable, List(Of String))
Dim connectionString = (Convert.ToString("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=") & fileName) + ";Extended Properties=Excel 12.0;"
Dim adapter = New OleDbDataAdapter((Convert.ToString("SELECT * FROM [") & sheetName) + "]", connectionString)
Dim ds = New DataSet()
adapter.Fill(ds, tblName)

Dim dt = ds.Tables(tblName)

Dim excelColumnHeaders = dt.Columns.Cast(Of DataColumn)().[Select](Function(x) x.ColumnName).ToList()

Return Tuple.Create(dt, excelColumnHeaders)
End Function

Comments or Responses

Login to post response