Click here to Skip to main content
15,891,629 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Error=columnName Does not exist

Code:
C#
foreach (DataTable dt in ds.Tables)
{
    foreach (DataColumn dc in dt.Columns)
    {
        columnName.Add(dc.ColumnName.ToString());
    }
}

for (j = 0; j <= ds.Tables[0].Columns.Count - 1; j++)
{
    xlWorkSheet.Cells[1, j + 1] = columnName[j].ToString();
}
Posted
Updated 26-Feb-15 21:41pm
v2
Comments
Suvendu Shekhar Giri 27-Feb-15 3:43am    
Can you please share the code where you have declared "columnName" ?

1 solution

can you please check like this...


C#
foreach (DataTable dt in ds.Tables)
            {
                for (int i = 0; i < dt.Columns.Count; i++)
                {
                    xlWorkSheet.Cells[1, i + 1] = dt.Columns[i].ColumnName;
                }
            }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900