?
Solved

Oldedb Excel create table command is converting hyphens into underscores

Posted on 2010-08-25
6
Medium Priority
?
1,480 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
  • 2
  • 2
5 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 2000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

862 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