SQL命令使用参数语法错误

时间:2015-04-14 23:20:45

标签: sql

您好我是sql和c#查询的新手。我在使用SQL时使用了select语句和puttin @参数。

string cmd = "select (FirstName, LastName, Address, City, PostalCode, Country, Username) values (@FirstName, @LastName, @Address, @City, @PostalCode, @Country, @Username) from [Customer];";

它不喜欢我的sql任何人都可以告诉我为什么?它说错误的语法,但我无法发现在哪里?

由于 DOM

2 个答案:

答案 0 :(得分:2)

SELECT语句用于从数据库中选择数据。

如果您想要检索数据,则不必添加values关键字:

SELECT column_name,column_name
FROM table_name;

使用您的查询:

string cmd = "SELECT FirstName, LastName, Address, City, PostalCode, 
              Country, Username FROM Customer;";

如果您想要使用参数检索数据,则这是语法:

SELECT column_name,column_name
FROM table_name
WHERE column_name operator value;

使用您的查询:

string cmd = "SELECT FirstName, LastName, Address, City, PostalCode, 
              Country, Username FROM Customer WHERE FirstName=@FirstName AND
              LastName=@LastName AND Address=@Address AND City=@City AND
              PostalCode=@PostalCode AND Country=@Country AND Username=@Username;";

尽管这不是真的正确,因为您只需检查您在客户表上设置的ID。

string cmd = "SELECT FirstName, LastName, Address, City, PostalCode, 
                  Country, Username FROM Customer WHERE *yourID*=*@yourID*;";

你可以试试这里:

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

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

答案 1 :(得分:1)

看看这个链接,你应该使用SELECT INTO语句。

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

SELECT column_name(s)
INTO newtable [IN externaldb]
FROM table1;