C# SQL语句中带有2个条件的WHERE子句

C# SQL语句中带有2个条件的WHERE子句,c#,sql,asp.net,sql-server,if-statement,C#,Sql,Asp.net,Sql Server,If Statement,我有以下aspx(html)代码: SQL中存在语法错误;而不是: query = "select * from customer where country = '" + country + "select * from customer where idcurrency = '" + idcurrency + "'"; 它应该如下所示: query = "select * from customer where country = '" + country + "' AND idcurre

我有以下aspx(html)代码:


SQL中存在语法错误;而不是:

query = "select * from customer where country = '" + country + "select * from customer where idcurrency = '" + idcurrency + "'";
它应该如下所示:

query = "select * from customer where country = '" + country + "' AND idcurrency = '" + idcurrency + "'";

希望这会有所帮助。

根据您当前的代码,无论您是否选择货币,在选择国家/地区时,都将始终执行下面的第一个
if

if (country != "select")
{
    query = "select * from customer where country = '" + country + "'";
}
您还需要在第一个
if
块中检查所选货币。我还修复了错误的SQL语法

if (country != "select")
{
    if (idcurrency != "selected")
    {
        query = "select * from customer where country = '" + country + "' and idcurrency = '" + idcurrency + "'";
    }
    else
    {
        query = "select * from customer where country = '" + country + "'";
    }
}

我们无法为您调试所以投票关闭哦!这只是搜索客户文本框的一个条件,先生,获取客户的值,我获取文本框id=“search”的值并将其放入字符串customer=(this.search.value);不客气!我很高兴它能为您服务。请检查已接受的答案,如果您还有更多问题,请单独发布。祝您项目顺利。致以问候,这项工作,先生,非常感谢!:)一个问题:如果我的国家和货币与其数据库不匹配,我应该将警报标签放在哪里?
query = "select * from customer where country = '" + country + "' AND idcurrency = '" + idcurrency + "'";
if (country != "select")
{
    query = "select * from customer where country = '" + country + "'";
}
if (country != "select")
{
    if (idcurrency != "selected")
    {
        query = "select * from customer where country = '" + country + "' and idcurrency = '" + idcurrency + "'";
    }
    else
    {
        query = "select * from customer where country = '" + country + "'";
    }
}