简体   繁体   中英

ERROR:Make sure that it does not include invalid characters or punctuation and that it is not too long

I try to get excel sheet names, with oledb.

My connection string is:

string ConnString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=Excel 12.0;";

where filepath is a filename.

My code for this:

 OleDbCommand cmd = new OleDbCommand(@"SELECT * FROM [Employee$]", conn);
                OleDbDataAdapter adapter = new OleDbDataAdapter(cmd);
                adapter.Fill(Data);

Get an Error in this line

adapter.Fill(Data);

Error is

'System.Data.OleDb.OleDbException' occurred in System.Data.dll
Additional information: 'Employee$' is not a valid name. Make sure that it does not include invalid characters or punctuation and that it is not too long.

How can this be Done?

Try this:

 OleDbCommand cmd = new OleDbCommand(@"SELECT * FROM [dataGridView1_Data$]", conn);
 OleDbDataAdapter adapter = new OleDbDataAdapter(cmd);
            adapter.Fill(Data);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM