tags:

views:

19

answers:

1

I am using Oledb driver to load data from excel for displaying in tabcontrol with datargids

I am using following loop to load data from every sheet

foreach (string str in sheets)
                {

                    string query = "SELECT * FROM [" + str + "]";


                    adapter.SelectCommand.CommandText = query;
                    adapter.Fill(ds,str);
                }

It works well until sheet names start with numbers. I have a excel file whose sheet name is 26203 REV C (EVK). It throws me error as The Microsoft Jet database engine could not find the object ''26203 REV C [EVK]$'_'. Make sure the object exists and that you spell its name and the path name correctly.What can be the remedy to the problem. I do not have any control over the sheet names.

+1  A: 

Try using backticks (`) instead of brackets:

SELECT * FROM `26203 REV C (EVK)$`

Remember that you also need to include the dollar symbol suffix when selecting.

Richard Szalay