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
Solved

Oldedb Excel create table command is converting hyphens into underscores

Posted on 2010-08-25
6
1,397 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
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Problem to line 23 53
Application.FileSearch does not work in excel 2016 2 17
Access Schema 6 23
Add Attendee Macro need not halt for Acknowledgement 12 21
Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

808 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