我的存储过程如下:
CREATE proc smsget2_update    
as
set nocount on
select top 20000 id,tel,msg into #msg from smsmsg WITH (NOLOCK) where id not in (select id from smsmsg_id)insert into smsmsg_id(id) select id from #msg   --如果去掉这一行ADO就能正常访问结果集select tel,dbo.f_getmsg(msg),name,username,origin from #msg
set nocount off
GO现在我用ADO调用这个存储过程,访问的结果集老是为空的
连接数据库的VC代码如下:
_ConnectionPtr m_pConn;
m_pConn.CreateInstance(__uuidof(Connection));
CString openStr;
openStr.Format(_T("Provider=SQLOLEDB;driver={SQL Server};Server=%s;DATABASE=%s;UID=%s;PWD=%s"),
serverName, dbName, userName, password);
_bstr_t bOpenStr = openStr;
m_pConn->Open(bOpenStr, _T(""), _T(""), adModeUnknown);///连接SQL Server数据库_variant_t RecordsAffected;
RecordsAffected.vt = VT_I4;
RecordsAffected.intVal = 0;_bstr_t sqlStr = "smsget2_update";
_RecordsetPtr m_pRS= conn.m_pConn->Execute(sqlStr, &RecordsAffected, adCmdStoredProc);if(m_pRS->adoEOF)
m_pRS->MoveFirst();
while(!m_pRS->adoEOF)
{
//操作代码,可是程序里面这个循环一直进不来。用查询分析器里面可以查询出三条记录
}现在如果在smsget2_update 这个存储过程的最开始加上truncate table smsmsg_id,ADO也能进入while循环。或者把那个
insert into smsmsg_id(id) select id from #msg去除也能进入while循环。请各位高手们支招...先谢谢了!注,换成##msg也不行

解决方案 »

  1.   

    在存储过程里加上事物语句,然后commit,看看是否还有问题。
      

  2.   

    在存储过程前后加了
    begin   tran
    commit   tran
    还是不行。
      

  3.   

    昨天又发现一个问题,如果把select top 20000 id,tel,msg into #msg from smsmsg WITH (NOLOCK) where id not in (select id from smsmsg_id)
    最后的id not in(select id from smsmsg_id)去除,也能正常访问到结果集
      

  4.   


    if(m_pRS->adoEOF)
    m_pRS->MoveFirst();
    while(!m_pRS->adoEOF)
    {
    //操作代码,可是程序里面这个循环一直进不来。用查询分析器里面可以查询出三条记录
    //是不是没有在循环中添加m_pRS->MoveNext();
    }
      

  5.   

    在存储过程里加上事物语句,然后commit,看看是否还有问题。