需要有关SQL Query SQLserver或Access的帮助

时间:2014-12-18 10:44:49

标签: sql sql-server ms-access

我有一个datagrid:

enter image description here

我希望列出logo=truechair=truecolor=true,但name IS NOT NULL值。

我试过了:

SELECT 
    name,
    logo,
    chair,
    color 
FROM 
    Mytable 
WHERE 
    logo = True OR chair = True OR color = True 
    AND name IS NOT NULL

但是这个查询列出了所有列。

我知道我的查询不好,但我找不到错误。

如何解决这个问题?

在这里编辑我的完整代码:

  Try
        Dim dt As New DataTable()
        Dim con As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source='" & Application.StartupPath & "\db.mdb';")
        Dim cmd As New OleDbCommand("Select * from table WHERE (chair = 'true' or color = 'true' or logo = 'true') and name is not null", con)
        Dim adap As New OleDbDataAdapter(cmd)
        adap.Fill(dt)
        DataGridView1.DataSource = dt
        DataGridView1.Columns(0).HeaderText = "Name"
        DataGridView1.Columns(1).HeaderText = "Logo"
        DataGridView1.Columns(2).HeaderText = "Chair"
        DataGridView1.Columns(3).HeaderText = "Color"
        dt = Nothing
        con = Nothing
        cmd = Nothing
        adap = Nothing
    Catch ex As Exception

    End Try

1 个答案:

答案 0 :(得分:1)

对于SQL Server :尝试将()置于OR条件的周围,同样您需要将''放在值True附近像这样:

Select 
  name,logo,chair,color 
From Mytable 
Where (logo = 'True' or chair = 'True' or color = 'True')
  And name Is Not Null;

这假定使用数据类型logo(布尔值)声明chaircolorbit