I am importing excel files to my application and sometimes worksheets column names have "$" sign in it. I receive this Exception:
System.Data.OleDb.OleDbException was unhandled
Message=''6um$'$' is not a valid name. Make sure that it does not include invalid characters or punctuation and that it is not too long.
In this sheet "6um$" is a column name.
This is my code:
OleDbConnection con = new System.Data.OleDb.OleDbConnection(connectionString);
OleDbDataAdapter cmd = new System.Data.OleDb.OleDbDataAdapter(
"select * from [" + worksheetName + "$]", con);
con.Open();
System.Data.DataSet excelDataSet = new DataSet();
cmd.Fill(excelDataSet);
con.Close();
Any ideas how to handle this situation?
Edit:
I thought the problem was having $ in column name. But turns out, The problem is having $ sign in worksheet name!