Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/126.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/docker/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++如何使两个语句SQL与OLeDB一起工作?_C++_Sql Server_Oledb - Fatal编程技术网

C++如何使两个语句SQL与OLeDB一起工作?

C++如何使两个语句SQL与OLeDB一起工作?,c++,sql-server,oledb,C++,Sql Server,Oledb,我有以下SQL语句: USE "ws_results_db_2011_09_11_09_06_24";SELECT table_name FROM INFORMATION_SCHEMA.Tables WHERE table_name like 'NET_%_STAT' order by table_name 我使用下面的C++代码执行: IDBCreateCommandPtr spDBCreateCommand = GetTheDBCreateCommandPointer(); IComman

我有以下SQL语句:

USE "ws_results_db_2011_09_11_09_06_24";SELECT table_name FROM INFORMATION_SCHEMA.Tables WHERE table_name like 'NET_%_STAT' order by table_name
我使用下面的C++代码执行:

IDBCreateCommandPtr spDBCreateCommand = GetTheDBCreateCommandPointer();
ICommandTextPtr spCommandText;
spDBCreateCommand->CreateCommand(NULL, IID_ICommandText, reinterpret_cast<IUnknown **>(&spCommandText));
spCommandText->SetCommandText(DBGUID_SQL, GetTheQueryText());
IRowsetPtr spRowset;
spCommandText->Execute(NULL, IID_IRowset, NULL, NULL, reinterpret_cast<IUnknown **>(&spRowset));
RowHandles hRows(spRowset, 0);
ULONG   rowCount;
ULONG maxRowCount = 1;
spRowset->GetNextRows(DB_NULL_HCHAPTER, 0, maxRowCount, &rowCount, hRows.get_addr());
注二:

为了简洁起见,省略了错误处理 RowHandles实现了HROW的RAII概念* 无论如何,我无法执行这两条SQL语句。发生的情况是spCommandText->Execute返回S_OK,但将spRowset设置为NULL

如果在调试会话期间通过向后移动指令指针来执行相同的spCommandText->execute第二次,则返回一个有效的IRowset指针-我使用它成功地获得了正确的列信息。但是spRowset->GetNextRows将rowCount设置为0,并返回DB_S_ENDOFROWSET-不走运

当我执行一条SQL语句时,代码运行良好

我做错了什么


谢谢。

由客户机来分割sql命令-isql在;ie您要求使用和选择两个命令。 因此,修复方法是通过单独的createCommand集执行这两个命令并执行

还要注意,在这种情况下,可以将命令作为一条SQL语句来执行

SELECT table_name FROM ws_results_db_2011_09_11_09_06_24.INFORMATION_SCHEMA.Tables 
  WHERE table_name like 'NET_%_STAT' 
  order by table_name