我想查询数据,列(大陆)的值为'Africa'或Null。
我想在我的查询中使用此列名称,但对于名称不是非洲的国家/地区,我没有数据。
这是我尝试的但没有返回数据。
SqlDataAdapter dba = new SqlDataAdapter(@"SELECT * from [tblCountries]
WHERE [Continent] = '' order by [Common Name]", connection);
//WHERE [Continent]<>'Africa' order by [Common Name]", connection);
//WHERE [Continent] IS null order by [Common Name]", connection);
dba.Fill(ds);
drpNonAfricanCountries.DataSource = ds;
这样做的正确方法是什么?
答案 0 :(得分:3)
我想查询数据,列(Continent)的值为 '非洲'或无。
WHERE [Continent] = 'Africa' OR [Continent] IS NULL
使用NULL
使用IS NULL
所以你的最终代码应该是:
SqlDataAdapter dba = new SqlDataAdapter(@"SELECT * from [tblCountries]
WHERE [Continent] = 'Africa' OR [Continent] IS NULL order by [Common Name]", connection);
答案 1 :(得分:1)
试试这个
SqlDataAdapter dba = new SqlDataAdapter(@"SELECT * from [tblCountries]
WHERE [Continent] IS NULL order by [Common Name]", connection);
dba.Fill(ds);
drpNonAfricanCountries.DataSource = ds;
答案 2 :(得分:1)
select * from tblCountries where (Continent = 'Africa' or Continent is null)
答案 3 :(得分:1)
试试这个:
SELECT [from [tblCountries] WHERE [Continent] IS NULL或[Continent] ='Africa'的顺序由[Common Name];