我在程序中作了一个查询按钮如下
Private Sub Cmdser_Click()
Dim str As Variant
If Text1.Text <> "" Then
   str = "yhmc like '%" & Text1.Text & "%'"
End If
If Text2.Text <> "" Then
   If str = "" Then
      str = "yhkl like '%" & Text2.Text & "%'"
   Else
      str = str & " and yhkl like '%" & Text2.Text & "%'"
   End If
End If
Adodc1.Recordset.Filter = str---------------错误指向这里
end sub
如果是这样的话,按钮是好用的而且能够查找到数据
Adodc1.CommandType = adCmdText
Adodc1.RecordSource = "select * from   companyuser order by xuhao"
Adodc1.Refresh
但是如果改成这个样子的话就会抱错:"在所对应的名称或序数集合中,未找到项目"
Adodc1.CommandType = adCmdText
Adodc1.RecordSource = "select xuhao as 序号,yhmc as 名称,yhkl as  密码,yhqx as 权限 ,js as 数值,lr as 录入人 from   companyuser order by xuhao"
Adodc1.Refresh
还请各位高手指点指点

解决方案 »

  1.   

    --select xuhao as 序号,yhmc as 名称,yhkl as  密码,yhqx as 权限 ,js as 数值,lr as 录入人
    你这里把数据集的列名用as做了别名 那么filter 过滤就根据别名来
    If Text1.Text  < > "" Then 
       str = "名称 like  '%" & Text1.Text & "% '" 
    End If 
    If Text2.Text  < > "" Then 
       If str = "" Then 
          str = "密码 like  '%" & Text2.Text & "% '" 
       Else 
          str = str & " and 密码 like  '%" & Text2.Text & "% '" 
       End If 
    End If 
      

  2.   

    如果是用 DataGrid 显示查询结果的话,建议你通过编辑 DataGrid 的属性来设置列标题的显示文字,而不要更改查询语句。
      

  3.   

    少用ado控件,多用ado代码控件绑定太严Adodc1.CommandType = adCmdText
    Adodc1.RecordSource = "select xuhao as 序号,yhmc as 名称,yhkl as  密码, 
    yhqx as 权限 ,js as 数值,lr as 录入人 from   companyuser order by xuhao"
    Adodc1.Refresh 我看没什么错误
      

  4.   

    少用ado控件,多用ado代码?
    有什么好处?
      

  5.   

    ayalicer 老兄说的不错,以下就改过来了