I have to implement a file upload feature in which users are allowed to upload files containing tabular data. On uploading the file I want to find the column names of table.
@vc 74 I would like to point out some mistake in code:
Instead of having sheetColumns.Rows
, there should be sheetColumns.Columns
as it was already referencing to DataColumn type.
To read all the column names existing in particular sheet of excel file, DataRow should be referenced as below:
After opening the connection, code goes like this:
DataTable dt = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Columns, new object[]
{ null,null, sheetName, null });
List<string> listColumn = new List<string>();
foreach (DataRow row in dt.Rows)
{
listColumn.Add(row["Column_name"].ToString());
}
listColumn contains the column names existing in the specified sheet.