使用我的sql语句获取不正确的WHERE语法

时间:2017-04-07 09:19:04

标签: sql sql-server

希望有人可以提供帮助,我继续使用以下sql语句获取不正确的“WHERE”语法

using (SqlCommand selectT = new SqlCommand("Select [TR_RegNumber] 
                                            FROM dbo.TrailerDetail 
                                            WHERE [TR_Routes] = '" +trailersRoutesAllocations[i]+ "'" + " 
                                            AND WHERE [TR_Classficiation] = '" +trailersVragClassification[i]+ "'", con))

我在C#中编码(使用Visual Studio)

2 个答案:

答案 0 :(得分:2)

你还有一个。只写一个像这里的地方:

SELECT column1, column2, ...
FROM table_name
WHERE condition1 AND condition2 AND condition3 ...;

这是https://www.w3schools.com/sql/sql_and_or.asp

的副本

答案 1 :(得分:0)

删除AND条件中的额外位置,它应该有效。

using (SqlCommand selectT = new SqlCommand("Select [TR_RegNumber] 
                                        FROM dbo.TrailerDetail 
                                        WHERE [TR_Routes] = '" +trailersRoutesAllocations[i]+ "'" + " 
                                        AND [TR_Classficiation] = '" +trailersVragClassification