'得到当前日期的销售额列名
        dte_selldate = CStr(dte_date(int_i))
        '生成执行的SQL语句
        str_sqlsell = "select xbm,lvbm," & "[" & dte_selldate & "]" & " from t_sell1"
        'Debug.Print str_sqlsell
        ado_retsell.Open str_sqlsell, ado_conn, adOpenKeyset, adLockOptimistic
        
        If ado_retsell.RecordCount = -1 Then
            MsgBox ado_retsell.RecordCount
            GoTo PROC_EXIT
        End If
               
        ado_retsell.MoveFirst这段程序中的SQL语句执行完,总是返回空的记录集,这是为什么,请高手帮忙看一下!

解决方案 »

  1.   

    对了我用的数据库是SQL Server 2000 sp3 ,在Access 2000中没有任何问题,到SQL Server中就不行
      

  2.   

    使用RecordCount要确保Connection的CursorType是客户端游标。要不然不会返回正确的值。
      

  3.   

    '这样试一下。 str_sqlsell = "select xbm,lvbm," & "'" & dte_selldate & "'" & " from t_sell1"
      

  4.   

    所以有可能Recordset并不空,只是你的判断语句不对。要么强制设定游标为客户端游标,要么用记录集的 EOF 和BOF 联合判断。
      

  5.   

    这个问题已解决,在ret.open之前加入
    ret.CursorLocation = adUseClient
    就OK了,我太大意了,看看朋友们对这段程序还有什么其它的意见
      

  6.   

    ..........
    ret.CursorLocation = adUseClient--->加這句
    ado_retsell.Open str_sqlsell, ado_conn, adOpenKeyset, adLockOptimistic
    .........
    ..