Private Sub Cmdsearch_Click()
Dim strsql As String
If Combo1.Text = Combo1.List(0) Then
 strsql = "select * from 书籍信息表 where 书籍名称 ='" & txtin.Text & "'"
Else
  If Combo1.Text = Combo1.List(1) Then
     strsql = "select * from 书籍信息表 where 书籍著者 ='" & txtin.Text & "'"
  Else
    If Combo1.Text = Combo1.List(2) Then
      strsql = "select * from 书籍信息表 where 出版社 ='" & txtin.Text & "'"
    End If
 End If
End If
Adodc1.RecordSource = strsql
Adodc1.Refresh
运行后 提示from 子句语法错误。 Adodc1.Refresh 显黄色,应该怎么办?

解决方案 »

  1.   

    不行,提示说 extcute 方法没有定义
      

  2.   

    Adodc1.CommandType = adCmdText
      

  3.   

    在最后一个end if 后加上一句Adodc1.CommandType = adCmdText
      

  4.   

    问题解决,能说一下 Adodc1.CommandType = adCmdText 的功能是什么吗?
      

  5.   

    CommandType 属性 (ADO)
             指示 Command 对象的类型。设置和返回值设置或返回以下某个 CommandTypeEnum 值。常量 说明 
    AdCmdText 将 CommandText 作为命令或存储过程调用的文本化定义进行计算。 
    AdCmdTable 将 CommandText 作为其列全部由内部生成的 SQL 查询返回的表格的名称进行计算。 
    AdCmdTableDirect 将 CommandText 作为其列全部返回的表格的名称进行计算。 
    AdCmdStoredProc 将 CommandText 作为存储过程名进行计算。 
    AdCmdUnknown 默认值。CommandText 属性中的命令类型未知。 
    AdCommandFile 将 CommandText 作为持久 Recordset 文件名进行计算。 
    AdExecuteNoRecords 指示 CommandText 为不返回行的命令或存储过程(例如,插入数据的命令)。如果检索任意行,则将丢弃这些行且并不返回。它总是与 adCmdText 或 adCmdStoredProc 进行组合。 
    说明使用 CommandType 属性可优化 CommandText 属性的计算。如果 CommandType 属性的值等于 adCmdUnknown(默认值),系统的性能将会降低,因为 ADO 必须调用提供者以确定 CommandText 属性是 SQL 语句、还是存储过程或表格名称。如果知道正在使用的命令的类型,可通过设置 CommandType 属性指令 ADO 直接转到相关代码。如果 CommandType 属性与 CommandText 属性中的命令类型不匹配,调用 Execute 方法时将产生错误。adExecuteNoRecords 常量通过最小化内部处理来提高性能。该常量不独立使用,它总是与 adCmdText 或 adCmdStoredProc 组合(如 adCmdText+adExecuteNoRecords)一起使用。如果与 Recordset.Open 一起使用 adExecuteNoRecords,或者该方法使用 Command 对象都将产生错误。
      

  6.   

    Dim strsql As String
    If Combo1.Text = Combo1.List(0) Then
     strsql = "select * from 书籍信息表 where 书籍名称 ='" & txtin.Text & "'"
    Else
      If Combo1.Text = Combo1.List(1) Then
         strsql = "select * from 书籍信息表 where 书籍著者 ='" & txtin.Text & "'"
      Else
        If Combo1.Text = Combo1.List(2) Then
          strsql = "select * from 书籍信息表 where 出版社 ='" & txtin.Text & "'"
        End If
     End If
    End If
    adodc1.execute(strsql)