Click here to Skip to main content
15,883,901 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am creating a simple software in vb net that open a connection to a sql server in which the name of the table that i need to retreive cointains an exclamation mark, the string for the sql statement i am using is the following.

Dim strSQL As String
strSQL = "select * from dbo.!Lotti"

dbo.!Lotti is the actual the name of what I am looking for.

the problem is that the exclamation mark is causing a lot of problems, since the program is telling me there is syntax error with "!".

What I have tried:

I have tried to connect to a different table with no ! in the name, everything went fine. So the problem is the ! itself.

Tried using
strSQL = "select * from [dbo.!Lotti]"
strSQL = "select * from ['dbo.!Lotti']"
strSQL = "select * from '[dbo.!Lotti]'"

UPDATE:
tried also
strSQL = "select * from [dbo.!Lotti]" and says invalid object name. We tried creating a copy of the database wite name dbo.Lotti and it works like this:

strSQL = "select * from dbo.Lotti" 

but not like this:
strSQL = "select * from [dbo.Lotti] " 
(says invalid object name)
Posted
Updated 11-Oct-17 2:36am
v2
Comments
Wessel Beulink 11-Oct-17 8:29am    
Remove the exclamation mark from the table name... isn't that hard...
Karthik_Mahalingam 11-Oct-17 8:31am    
have tried this
 cmd.CommandText = "select * from [dbo.!Lotti] "; 

works fine.
Member 12704629 11-Oct-17 8:38am    
Tried but not working :(, i have updated the question with your try.
Karthik_Mahalingam 11-Oct-17 8:39am    
Which version of sql are you using
Member 12704629 11-Oct-17 8:41am    
sql server 2014

1 solution

Try:
VB
strSQL = "select * from dbo.[!Lotti]"
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900