I have a datagrid:
我有一个datagrid:
and I want to list if logo=true
or chair=true
or color=true
, but name IS NOT NULL
values.
我想列出如果logo = true或chair = true或color = true,但名称是IS NOT NULL值。
I tried:
SELECT
name,
logo,
chair,
color
FROM
Mytable
WHERE
logo = True OR chair = True OR color = True
AND name IS NOT NULL
But this query lists all the columns.
但是此查询列出了所有列。
I know my query is bad, but I can not find error.
我知道我的查询很糟糕,但我找不到错误。
How to fix this problem?
如何解决这个问题?
Post edit here my full code:
在这里编辑我的完整代码:
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 个解决方案
#1
1
For SQL Server: Try to put ()
around the OR
s conditions, also you need to put ''
around the values True
like this:
对于SQL Server:尝试在ORs条件周围放置(),你还需要在这些值周围加上'':
Select
name,logo,chair,color
From Mytable
Where (logo = 'True' or chair = 'True' or color = 'True')
And name Is Not Null;
This assuming that logo
, chair
, and color
are declared with data type bit
(boolean).
假设徽标,椅子和颜色是用数据类型bit(boolean)声明的。
#1
1
For SQL Server: Try to put ()
around the OR
s conditions, also you need to put ''
around the values True
like this:
对于SQL Server:尝试在ORs条件周围放置(),你还需要在这些值周围加上'':
Select
name,logo,chair,color
From Mytable
Where (logo = 'True' or chair = 'True' or color = 'True')
And name Is Not Null;
This assuming that logo
, chair
, and color
are declared with data type bit
(boolean).
假设徽标,椅子和颜色是用数据类型bit(boolean)声明的。