Solved

Oldedb Excel create table command is converting hyphens into underscores

Posted on 2010-08-25
6
1,414 Views
Last Modified: 2013-11-17
Hi,

I'm creating an excel file with vb.net and ole db.  The table (worksheet) name has hyphens in it.  The hyphens (-) are being converted to underscores (_) when I execute the create table command.

Here is the code:
mcliOLEDBCn = New System.Data.OleDb.OleDbConnection(Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & astrPathAndFile & ";Mode=ReadWrite;Extended Properties=""Excel 8.0;HDR=YES"")

mcliOLEDBCom = New OleDbCommand("CREATE TABLE [AR-08-25-2010] ([ITEMNO] MEMO , [QUANTITY] int)", mcliOLEDBCn)
mcliOLEDBCn.Open()                
mcliOLEDBCom.ExecuteNonQuery()

The worksheet inside the excel file ends up named as AR_08_25_2010 instead of AR-08-25-2010.

I am using visual studio 2008, vb, and windows 7.  I tried it with the ace provider for excel 2007 and got the same result.

How do I insert hyphens into the table name?

Any help would be appreciated.  Thanks!

-William
0
Comment
Question by:WilliamAK
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
6 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 33526204
Frankly, I don't believe that Excel supports table names with dashes, since they would be easily confused with the subtract operator.  I don't know of any way to tell the OLEDB provider to allow that kind of name.
0
 
LVL 17

Expert Comment

by:calacuccia
ID: 33526549
Have you tried using a back quote?

mcliOLEDBCom = New OleDbCommand("CREATE TABLE [`AR-08-25-2010`] ([ITEMNO] MEMO , [QUANTITY] int)", mcliOLEDBCn)
mcliOLEDBCn.Open()                
mcliOLEDBCom.ExecuteNonQuery()
0
 

Author Comment

by:WilliamAK
ID: 33531839
Thanks for the replies.

TheLearnedOne, if I rename the sheet in excel to AR-08-25-2010 and then query it with lcon.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, Nothing) it shows as 'AR-08-25-2010$' but if i try to create table using single quotes it still converts the hyphens to underscores (but also changes the last quote to an underscore and sheet is unopenable, very strange.)  And if i try using single quotes and the dollar symbol I get a syntax error in CREATE TABLE.

Calacuccia, if I use a back quote i get a syntax error in CREATE TABLE.

I'm not really sure what the $ is for, maybe it means a temporary sheet or an instance sheet or something.
0
 
LVL 17

Accepted Solution

by:
calacuccia earned 500 total points
ID: 33532007
The $ is the real sheet name and needed to read an Excel table correctly.
And Excel perfectly accepts hyphens for sheet names, as you could test for yourself.

The $ symbol should not be use to Create a new table.

You found yourself that you need [] to correctly read a file with hyphens....

I'm afraid the hyphen being converte to underscores is part of OLEDB syntax ...I've been googling a long time yesterday without any idea how to get around this.

Is it possible to change the name of the worksheet from your VB Project once it's created?

myWB.Worksheets("AR_08_25_2010").Name = "AR-08-25-2010"


0
 

Author Comment

by:WilliamAK
ID: 33541771
Yes, I'll have to come up with some kind of workaround.  The app runs on a server that does not have office installed.

Thanks for the replies Calacuccia.  :)
0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question