syntax problem with select command

Discussion in 'ASP .Net' started by Mich, Aug 15, 2007.

  1. Mich

    Mich Guest

    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
     
    Mich, Aug 15, 2007
    #1
    1. Advertising

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

    --
    Regards
    Pawel Potasinski
    [http://www.potasinski.pl]


    U¿ytkownik "Mich" <> napisa³ w wiadomo¶ci
    news:uOe%...
    > 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
    >
     
    Pawel Potasinski, Aug 15, 2007
    #2
    1. Advertising

  3. 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" <> wrote in message news:uOe%...
    > 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
    >
    >
     
    Tibor Karaszi, Aug 15, 2007
    #3
  4. Mich

    Mich Guest

    Thanks for replying. It works now.

    "Tibor Karaszi" <> schreef
    in bericht news:...
    > 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" <> wrote in message
    > news:uOe%...
    >> 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
     
    Mich, Aug 15, 2007
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    1
    Views:
    336
    Karl Seguin [MVP]
    Nov 9, 2006
  2. gabriele renzi
    Replies:
    2
    Views:
    204
    gabriele renzi
    Dec 31, 2005
  3. Ken Bloom
    Replies:
    3
    Views:
    212
  4. Good Night Moon
    Replies:
    9
    Views:
    283
    Rick DeNatale
    Jul 25, 2007
  5. palmiere
    Replies:
    1
    Views:
    411
    Erwin Moller
    Feb 9, 2004
Loading...

Share This Page