Displaying selected values only in VB6

馋奶兔 提交于 2019-12-31 07:31:19

问题


I am trying to display students in a datagrid that have "yes" as active. If the student has "no" as active, the form has to hide it and only show the students with "yes". The problem that I am recieving now is

Syntax error in FROM clause.

code:

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

回答1:


What is Active?
If Active is Boolean data type (Yes/No), it's optional values are True or False. In that case your query is:

"select * from Table1 where Active <> False"

If Active is String data type; are 'no' and 'No' the same values? you are better converting all to lower or upper case:

"select * from Table1 where Ucase(Active) <> 'NO'"

Edit: Modified Code

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


来源:https://stackoverflow.com/questions/38327403/displaying-selected-values-only-in-vb6

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!