我用adodc1从表中查找日期在一个范围之内的数据
sqlstr = "select * from pgd where pdrq>=""" + Format(dtpkfrom.Value, "YYYY-MM-DD") + """ and pdrq<=""" + Format(dtpkto.Value, "YYYY-MM-DD") + """"我跟踪后发现Adodc1.RecordSource = sqlstr后已经把数据查询出来了
但是紧接着在Adodc1.Refresh的是报错,搞不明白是哪的问题。错误内容如下:标准表达式中类型不匹配实时错误'-2147217913 (80040e070)';
对象'Refresh'的方法'IAdodc'失败
我用的ACCESS数据库

解决方案 »

  1.   

    在adodc1.refresh前面加一句 Adodc1.CommandType = adCmdText你可以试试一下,应该不出错的
      

  2.   

    不行还是出那个错以下是我那个过程的整个代码
    Private Sub cmdfind_Click()
    Dim sqlstr
    sqlstr = "select * from pgd where 1=1"If chkfzr.Value = 0 And chklb.Value = 0 And chkdata.Value = 0 Then
      MsgBox "&Ecirc;&auml;&Egrave;&euml;&Ograve;&ordf;&sup2;é&Ntilde;&macr;&micro;&Auml;&Igrave;&otilde;&frac14;&thorn;&pound;&iexcl;", vbInformation, "&Igrave;á&Ecirc;&frac34;"
    Else
      If chkfzr.Value = 1 And cmbfzr.ListIndex = -1 Then
      MsgBox "&Ecirc;&auml;&Egrave;&euml;&Ograve;&ordf;&sup2;é&Ntilde;&macr;&micro;&Auml;&Igrave;&otilde;&frac14;&thorn;&pound;&iexcl;", vbInformation, "&Igrave;á&Ecirc;&frac34;"
      Else
        If chklb.Value = 1 And cmblb.ListIndex = -1 Then
        MsgBox "&Ecirc;&auml;&Egrave;&euml;&Ograve;&ordf;&sup2;é&Ntilde;&macr;&micro;&Auml;&Igrave;&otilde;&frac14;&thorn;&pound;&iexcl;", vbInformation, "&Igrave;á&Ecirc;&frac34;"
        Else
          If chkfzr.Value = 1 And cmbfzr.ListIndex <> -1 Then
            sqlstr = sqlstr + "and fzr=""" + cmbfzr.Text + """"
          End If
          If chklb.Value = 1 And cmbfzr.ListIndex <> -1 Then
            sqlstr = sqlstr + "and lb=""" + cmblb.Text + """"
          End If
          If chkdata.Value = 1 Then
            sqlstr = sqlstr + "and pdrq>=""" + Format(dtpkfrom.Value, "YYYY-MM-DD") + """ and pdrq<=""" + Format(dtpkto.Value, "YYYY-MM-DD") + """"
          End If
        End If
      End If
    End IfAdodc1.RecordSource = sqlstr
    Adodc1.CommandType = adCmdText
    Adodc1.Refresh
    DataGrid1.RefreshEnd Sub
      

  3.   

    搞定了
    把SQL改成
    sqlstr = sqlstr + "and pdrq>=" + "#" + Format(dtpkfrom.Value, "YYYY-MM-DD") + "#" + " and pdrq<=" + "#" + Format(dtpkto.Value, "YYYY-MM-DD") + "#" + ""
    就行了