Private Sub Command1_Click()
    Dim cn As New ADODB.Connection
    Dim cmd As New ADODB.Command
    Dim paramPlantCode As ADODB.Parameter
    Dim rs As New ADODB.Recordset
    
    
    cn.ConnectionString = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Password=sa;Initial Catalog=bic;Data Source=192.168.0.4"
    cn.Open
    cmd.ActiveConnection = cn
    cmd.CommandText = "bic_ii_stockcount"
    cmd.CommandType = adCmdStoredProc
    cmd.CommandTimeout = 1000    Set paramPlantCode = cmd.CreateParameter("modellcode", adChar, adParamInput, 2, "01")
    
    cmd.Parameters.Append paramPlantCode
    
    Set rs = cmd.Execute()
    While Not rs.EOF'到这里的时候报告3704错误:对象已关闭,不允许操作.
        rs.MoveNext
    Wend
End Sub上面while 时出错,原来好的。
奇怪

解决方案 »

  1.   

    可能是你的存储过程 'bic_ii_stockcount'有问题.贴出来看看!
      

  2.   

    CREATE PROCEDURE bic_ii_stockcount 
    @modellcode varchar(10)
    AS
    declare @tempdate datetime
    create table #t(d datetime, s int)
    declare cdw cursor for 
    select wdays from workcalendar where year(wdays)=year(getdate()) and month(wdays)=month(getdate())
    and day(wdays)<=day(getdate()) and working=1 order by wdays
    open cdw
    fetch next from cdw into @tempdate
    while @@fetch_status=0
    begin
    insert into #t (d,s)
    select top 1 @tempdate as td, stockcount from stock
    where stockdate<=@tempdate and modellcode=@modellcode
    order by td desc
    fetch next from cdw into @tempdate
    end
    close cdw
    deallocate cdw
    select * from #t order by d
    drop table #t
    GO
    应该没问题,我在查询分析器中执行过,有结果的
      

  3.   

    CREATE PROCEDURE bic_ii_stockcount 
    @modellcode varchar(10)
    AS/*加上一句:*/
    SET NOCOUNT ON
    ....
    ....