0

我想查询数据,并且列(大陆)的值为“非洲”或 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;

这样做的正确方法是什么?

4

4 回答 4

3

我想查询数据,并且列(大陆)的值为“非洲”或 Null。

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);
于 2013-05-20T11:00:53.390 回答
1

像这样试试

SqlDataAdapter dba = new SqlDataAdapter(@"SELECT * from [tblCountries] 
                                     WHERE [Continent] IS NULL order by [Common Name]", connection);
            dba.Fill(ds);
            drpNonAfricanCountries.DataSource = ds;
于 2013-05-20T11:02:32.357 回答
1
select * from tblCountries where (Continent = 'Africa' or Continent is null)
于 2013-05-20T11:05:50.350 回答
1

尝试这个:

SELECT * from [tblCountries] WHERE [Continent] IS NULL OR [Continent]= 'Africa' order by [Common Name];

于 2013-05-20T11:28:42.417 回答