Jump to content
Xtreme .Net Talk

Why Excel needs a $ after the Table name as opposed to Access or SQL [C#]


Recommended Posts

Posted

I am trying to write an application that can use either an Access or Excel Database file, I found that with the correct Connection Strings you can connect and manipulate either one (which is GREAT).

However oddly enough there seems to be a difference when calling/accessing the tables, my Access Database has a table called "Clients" and the Excel Database has a table/worksheet called "Clients" - logically accessing them would be the same... but it is not.

 

For example, the following works:


Access = ds = oDB.Read("SELECT DISTINCT [CLIENTS] FROM [Clients] ORDER BY [CLIENTS]");
Excel = ds = oDB.Read("SELECT DISTINCT [CLIENTS] FROM [Clients$] ORDER BY [CLIENTS]");
[/Code]

Notice the "$" in the "FROM [Clients]" part that differs, also note that both of these currently work fine as-is. If I don't put the $ for EXCEL I get the following error:

"System.Data.OleDb.OleDbException: The Microsoft Jet database engine could not find the object 'Clients'. Make sure the object exists and that you spell its name and the path name correctly."

 

As shown there is a difference between ACCESS and EXCEL, why? Is there a way to standardize this? I would hate to have to check if the user selected Excel or Access and modify my TableNames on the fly to match the required type.

Why would Excel need a "$" when calling a table when Access and SQL don't? Any clues how to get around this? Thanks,

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...