查询的代码:
m_pCommand.CreateInstance("ADODB.Command");
m_pCommand->ActiveConnection = m_cHisData.m_pConnection;
m_pCommand->CommandType = adCmdStoredProc;
m_pCommand->CommandText=_bstr_t(_T("PROC_QueryOriginalFilePathTest"));
m_pCommand->Parameters->Refresh();
m_pCommand->Parameters->GetItem((long)1)->Value = _variant_t((LPCSTR)sStartTime);
m_pCommand->Parameters->GetItem((long)2)->Value = _variant_t((LPCSTR)sStopTime);
m_pRecordset = m_pCommand->Execute(NULL,NULL,adCmdStoredProc);
int nRecordNum = 0;
while(!m_pRecordset->adoEOF)
{
nRecordNum++;
m_pRecordset->MoveNext();
}
if (nRecordNum != 0)
{
m_pRecordset->MoveFirst();
}
执行:m_pRecordset->MoveFirst()时
提示错误:
行集位置不能被重新启动可能是什么原因?有什么解决的方法吗?
m_pCommand.CreateInstance("ADODB.Command");
m_pCommand->ActiveConnection = m_cHisData.m_pConnection;
m_pCommand->CommandType = adCmdStoredProc;
m_pCommand->CommandText=_bstr_t(_T("PROC_QueryOriginalFilePathTest"));
m_pCommand->Parameters->Refresh();
m_pCommand->Parameters->GetItem((long)1)->Value = _variant_t((LPCSTR)sStartTime);
m_pCommand->Parameters->GetItem((long)2)->Value = _variant_t((LPCSTR)sStopTime);
m_pRecordset = m_pCommand->Execute(NULL,NULL,adCmdStoredProc);
int nRecordNum = 0;
while(!m_pRecordset->adoEOF)
{
nRecordNum++;
m_pRecordset->MoveNext();
}
if (nRecordNum != 0)
{
m_pRecordset->MoveFirst();
}
执行:m_pRecordset->MoveFirst()时
提示错误:
行集位置不能被重新启动可能是什么原因?有什么解决的方法吗?
ALTER PROCEDURE [dbo].[PROC_QueryOriginalFilePathTest] @StartTime datetime,--开始时间
@EndTime datetime --结束时间
AS
BEGINdeclare @StandID int--机组号
declare @PointID int--测点号
declare @StandName varchar(128)--机组名
declare @PointName varchar(128)--测点名
declare @DTime datetime --原始文件表获得时间
declare @FilePath varchar(200) --原始文件路径
declare @TableName varchar(128) --原始文件存储表名
declare @WarnState int --报警状态(0:正常;1:报警)
declare @sSQL varchar(8000)--查询执行语句
declare @UnionSQL varchar(500)
declare @Len int--执行语句长度
set @sSQL=''
set @UnionSQL='union all '
--创建游标查询机组信息
DECLARE Stand_Cursor scroll CURSOR FOR
SELECT StandID,StandName
FROM StandInfo
ORDER BY StandID ASC
OPEN Stand_Cursor
FETCH First FROM Stand_Cursor INTO @StandID, @StandName
WHILE @@FETCH_STATUS = 0--游标遍历,查询机组信息
BEGIN
-- 游标嵌套查询测点信息
DECLARE Point_Cursor scroll CURSOR FOR
SELECT PointID,PointName
FROM PointInfo where StandID=@StandID
ORDER BY PointID ASC
OPEN Point_Cursor
FETCH First FROM Point_Cursor INTO @PointID,@PointName
WHILE @@FETCH_STATUS = 0
BEGIN -- 创建嵌套游标查询特征值数据
DECLARE OFP_Cursor scroll CURSOR FOR select TableName,GetTime from ManageTable
where
StandName=@StandName
and
PointName=@PointName
and
ValidFlag=1
and
month(GetTime) >= month(@StartTime) and month(GetTime) <= month(@EndTime)
order by GetTime ASC
OPEN OFP_Cursor
FETCH First FROM OFP_Cursor INTO @TableName,@DTime
WHILE @@FETCH_STATUS = 0 --游标循环所有表名
BEGIN --循环开始
if not exists(select * from ManageTable
where
StandName=@StandName
and
PointName=@PointName
and
ValidFlag=1
and
month(GetTime) >= month(@StartTime) and month(GetTime) <= month(@EndTime))
set @sSQL=@sSQL+''
else
set @sSQL=@sSQL+'select StandID,PointID,DTime,FilePath,WarnState from ['+@TableName+']
where DTime >= '''+ convert(varchar(20),@StartTime,120)+ ''' and DTime <='''+convert(varchar(20),@EndTime,120)+''''
+ @UnionSQL FETCH NEXT FROM OFP_Cursor INTO @TableName,@DTime
END --循环结束
CLOSE OFP_Cursor
DEALLOCATE OFP_Cursor --查询测点的游标指向下一个测点
FETCH NEXT FROM Point_Cursor INTO @PointID,@PointName
END
CLOSE Point_Cursor;
DEALLOCATE Point_Cursor;--查询机组的游标指向下一个机组
FETCH NEXT FROM Stand_Cursor INTO @StandID, @StandName
END
CLOSE Stand_Cursor;
DEALLOCATE Stand_Cursor;
--去掉执行语句中多余部分和空格
set @Len=len(rtrim(@sSQL))-len(@UnionSQL)
set @sSQL=ltrim(left(@sSQL,@Len))EXEC (@sSQL)
PRINT @sSQL END存储过程是别人写的,请大家帮忙看看