C# SQL Server中的多个where子句

C# SQL Server中的多个where子句,c#,sql,sql-server,C#,Sql,Sql Server,我编写此查询是为了检查重复项,但无法获得多个位置。我得到的是“,”附近的语法错误 private static bool duplicate(Dictionary<TableKey, string> entry) { SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString);

我编写此查询是为了检查重复项,但无法获得多个位置。我得到的是“,”附近的语法错误

private static bool duplicate(Dictionary<TableKey, string> entry)
    {
        SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString);
        // TODO: Make changes to this command when new additions/modifications to the DB structure occur  
        string commandText = @"Select Barcode, FullName, Location, Notes, Category From Inventory " +
                             @"Where Barcode = @barcode, FullName = @fullname, Location = @location, " +
                             @"Notes = @notes, Category = @category";

        SqlCommand command = new SqlCommand(commandText, connection);

        command.Parameters.AddWithValue("@barcode", entry[TableKey.Barcode]);
        command.Parameters.AddWithValue("@fullname", entry[TableKey.FullName]);
        command.Parameters.AddWithValue("@location", entry[TableKey.Location]);
        command.Parameters.AddWithValue("@notes", entry[TableKey.Notes]);
        command.Parameters.AddWithValue("@category", entry[TableKey.Category]);

        command.Connection.Open();
        SqlDataReader reader = command.ExecuteReader();

        if (reader.HasRows)
            return true;
        else
            return false;
    }
我如何拥有多个where?我试过“和”和“和”

你应该用

状况

下面是使用和的示例

"Where Barcode = @barcode AND FullName = @fullname AND Location = @location AND " +
                             @"Notes = @notes AND Category = @category";

这应该很好用

@"Where Barcode = @barcode AND FullName = @fullname AND Location = @location AND " +
      @"Notes = @notes AND Category = @category";
查找重复项

SELECT COUNT(*) as cnt, * 
From Inventory
GROUP  BY Barcode, FullName, Location, Notes, Category
HAVING COUNT(*) > 1

您选择的所有值都与where子句中的值相同。执行此select语句如何有用?它将有助于找到重复的语句。它将寻找类似的条目。有更好的方法吗?你能给我指一下吗?我建议你在网上查阅一些基本的SQL教程,试着关注一下
WHERE子句
,了解何时使用
和| |或
Jeffery Haines
你没有阅读注释/答案吗?我想你需要重新学习一下你的SQL以及你对如何使用SQL的理解制定有效的sql语句。如果数据未在表中排序,请使用
orderby子句。。阅读SELECT DISTINCT vs SELECT
其他需要阅读的关键词是
拥有、分组依据、SELECT COUNT()方法
SELECT COUNT(*) as cnt, * 
From Inventory
GROUP  BY Barcode, FullName, Location, Notes, Category
HAVING COUNT(*) > 1