syntax problem with select command

M

Mich

Hi,

the table 'l0382_project1' exists in sql server. I can see it.
Now in asp.net, i want to check whether it exists but i get "invalid column
name":

1st attempt:
comd.CommandText = "SELECT COUNT(*) FROM sys.tables WHERE [name] =
[l0382_project1]"
connection.Open()
nr = comd.ExecuteScalar()

Invalid column name 'l0382_project1'.


2nd attempt:
comd.CommandText = "SELECT COUNT(*) FROM sys.tables WHERE [name] =
['l0382_project1']"
connection.Open()
nr = comd.ExecuteScalar()

Invalid column name 'l0382_project1'.


Could somebody tell me the right syntax, please?
Thanks
Mich
 
P

Pawel Potasinski

comd.CommandText = "SELECT COUNT(*) FROM sys.tables WHERE [name] =
N'l0382_project1'"
 
T

Tibor Karaszi

The name of the table in the context of your query is just a regular string, so the query should be:

WHERE [name] = 'l0382_project1'
 
M

Mich

Thanks for replying. It works now.

Tibor Karaszi said:
The name of the table in the context of your query is just a regular
string, so the query should be:

WHERE [name] = 'l0382_project1'


--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://sqlblog.com/blogs/tibor_karaszi


Mich said:
Hi,

the table 'l0382_project1' exists in sql server. I can see it.
Now in asp.net, i want to check whether it exists but i get "invalid
column name":

1st attempt:
comd.CommandText = "SELECT COUNT(*) FROM sys.tables WHERE [name] =
[l0382_project1]"
connection.Open()
nr = comd.ExecuteScalar()

Invalid column name 'l0382_project1'.


2nd attempt:
comd.CommandText = "SELECT COUNT(*) FROM sys.tables WHERE [name] =
['l0382_project1']"
connection.Open()
nr = comd.ExecuteScalar()

Invalid column name 'l0382_project1'.


Could somebody tell me the right syntax, please?
Thanks
Mich
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,054
Latest member
LucyCarper

Latest Threads

Top