user5671888
user5671888

Reputation:

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?

Upvotes: 2

Views: 20119

Answers (1)

Arthi
Arthi

Reputation: 1004

Try this:

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

Upvotes: 5

Related Questions