WilliamAK
asked on
Oldedb Excel create table command is converting hyphens into underscores
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.OleDbCon nection(Pr ovider=Mic rosoft.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.ExecuteNonQue ry()
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
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.OleDbCon
mcliOLEDBCom = New OleDbCommand("CREATE TABLE [AR-08-25-2010] ([ITEMNO] MEMO , [QUANTITY] int)", mcliOLEDBCn)
mcliOLEDBCn.Open()
mcliOLEDBCom.ExecuteNonQue
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
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.
Have you tried using a back quote?
mcliOLEDBCom = New OleDbCommand("CREATE TABLE [`AR-08-25-2010`] ([ITEMNO] MEMO , [QUANTITY] int)", mcliOLEDBCn)
mcliOLEDBCn.Open()
mcliOLEDBCom.ExecuteNonQue ry()
mcliOLEDBCom = New OleDbCommand("CREATE TABLE [`AR-08-25-2010`] ([ITEMNO] MEMO , [QUANTITY] int)", mcliOLEDBCn)
mcliOLEDBCn.Open()
mcliOLEDBCom.ExecuteNonQue
ASKER
Thanks for the replies.
TheLearnedOne, if I rename the sheet in excel to AR-08-25-2010 and then query it with lcon.GetOleDbSchemaTable(O leDbSchema Guid.Table s, 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.
TheLearnedOne, if I rename the sheet in excel to AR-08-25-2010 and then query it with lcon.GetOleDbSchemaTable(O
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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. :)
Thanks for the replies Calacuccia. :)