我正在尝试在数据网格中显示具有“是”状态的学生。如果学生的活动状态为“否”,则该表格必须将其隐藏,并且仅向学生显示“是”。我现在收到的问题是
FROM子句中的语法错误。
代码:
Private Sub Form_Load() Dim sql As String connSearch.Open connstr Adodc1.ConnectionString = conn.connstr sql = "select * from Table1 where Active <>" & "'No'" Adodc1.RecordSource = sql Set StudentTable.DataSource = Adodc1 Adodc1.Refresh Adodc1.Visible = False End Sub
什么Active啊 如果Active是Boolean数据类型(是/否),则其可选值是True或False。在这种情况下,您的查询是:
Active
Boolean
True
False
"select * from Table1 where Active <> False"
如果Active是String数据类型;是'no'和'No'相同的值?您最好将它们全部转换为小写或大写:
String
'no'
'No'
"select * from Table1 where Ucase(Active) <> 'NO'"
编辑:修改后的代码
Dim sql As String sql = "select * from Table1 where [Active] <> 'No'" Adodc1.ConnectionString = conn.connstr Adodc1.CommandType = adCmdText Adodc1.RecordSource = sql Set StudentTable.DataSource = Adodc1 Adodc1.Refresh Adodc1.Visible = False