locked
sql command RRS feed

  • Question

  • User-1599356091 posted

    why sql wont run this....

    sorry i'm new with sql

    select count (*) from mytable where name=?

     

    it says parameters can not be used in this query type....

    Sunday, February 10, 2013 4:29 PM

Answers

  • User-1716253493 posted

    in ms sql use like this :

    select count (*) from mytable where name=@name


    to add parameter then use like this

    cmd.Parameters.AddWithValue("@name","someone")

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, February 10, 2013 6:11 PM

All replies

  • User-2143599517 posted

    hi,

    sql basics:

    http://www.w3schools.com/sql/sql_select.asp

    regards,

    Sunday, February 10, 2013 4:43 PM
  • User1546878023 posted

    If I remember correctly the ? parameter is for MySql but anyway you need to pass the parameter, so the above code will definitely not run on its own, there has to be more code then that

    Sunday, February 10, 2013 4:46 PM
  • User-1599356091 posted

    so i have a table with a collumn name and i want to check if the name already exists how can i do that is not like that-?

    access works fine

    Sunday, February 10, 2013 4:52 PM
  • User1546878023 posted

    You can take a look at this example to see how to create a parameterized query as the one you are showing

    http://www.4guysfromrolla.com/webtech/092601-1.2.shtml

    Sunday, February 10, 2013 5:05 PM
  • User-2143599517 posted
    For finding the column exist or not
    SELECT
    * FROM sys.columns WHERE object_id = OBJECT_ID('dbo.yourTableName')

    or

    SELECT t.name AS table_name,
     SCHEMA_NAME(schema_id) AS schema_name,
     c.name AS column_name
     FROM sys.tables AS t
     INNER JOIN sys.columns c ON t.OBJECT_ID = c.OBJECT_ID
     WHERE c.name LIKE '%EmployeeID%'
     ORDER BY schema_name, table_name;

    for full description follow below link:
    http://msdn.microsoft.com/en-us/library/aa933204%28SQL.80%29.aspx

    regards,
    anj
    Sunday, February 10, 2013 5:16 PM
  • User-1599356091 posted

    i dont see any diffrence from mine = "SELECT FirstName, LastName, Title " & _                        "FROM Employees " & _                        "WHERE ((EmployeeID > ? AND HireDate > ?) AND Country = ?)"

    Sunday, February 10, 2013 5:17 PM
  • User-1599356091 posted

    You can take a look at this example to see how to create a parameterized query as the one you are showing

    http://www.4guysfromrolla.com/webtech/092601-1.2.shtml

     

    i dont see any diffrence from mine = "SELECT FirstName, LastName, Title " & _                        "FROM Employees " & _                        "WHERE ((EmployeeID > ? AND HireDate > ?) AND Country = ?)"

    Sunday, February 10, 2013 5:20 PM
  • User-1716253493 posted

    in ms sql use like this :

    select count (*) from mytable where name=@name


    to add parameter then use like this

    cmd.Parameters.AddWithValue("@name","someone")

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, February 10, 2013 6:11 PM