Search code examples
c#asp.netoledb

Check if column name was passed or determined


I'm handling a project on ASP. NET (C#) and am using Oledb to get information from an Excel and pass it to an Gridview... I've set the HDR parameter to true on the connection string so that it assumes the first rows as the column name. When theres isn't any name on the first row "F'Number'" title is assigned to that column column name. I need to determine if the column name was given from the first row name or was automattically asigned but don't know how... Any thoughts?


Solution

  • AFAIK there's no integrated solution for this, but cou can simply parse the header name

    var header = columns[i].Name;
    if (header.StartsWith("F")) {
        int colIndex;
        if (Int32.TryParse(header.Substring(1), out colIndex))
        {
            if (colIndex == i)
                // auto assigned
        }
    }