below is from MSDN,you can find a lot of technical article in MSDN if you search"stored procedure and VC"
good luckSteps To Reproduce Behavior
In the SQL Server 7.0 Query Analyzer select the test database Pubs.
Create the following stored procedure. This stored procedure returns a recordset and an out parameter count.if exists (select * from sysobjects where id = object_id(N'[dbo].[GetJobs]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop proc GetJobs
go
create proc GetJobs @id as int, @count as int [out] as
begin
Select @count = Count(*) from jobs where job_id >@id
Select * from jobs where job_id >@id
end
go
Use VC App Wizard to create a new console application and modify the code as follows:#include "stdafx.h"
#include "stdio.h"
#import "C:\PROGRA~1\COMMON~1\System\ado\msado15.dll" no_namespace rename ("EOF", "EOF2") struct InitOle {
InitOle() { ::CoInitialize(NULL); }
~InitOle() { ::CoUninitialize(); }
} _init_InitOle_; int main(int argc, char* argv[])
{
_variant_t varErr((long)0, VT_ERROR);
_CommandPtr comm(__uuidof(Command));
_ConnectionPtr conn(__uuidof(Connection)); _bstr_t connstr="Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=pubs;Data Source=(local)";
conn->Open(connstr, "", "", adConnectUnspecified);
comm->ActiveConnection=conn;
comm->CommandText="GetJobs";
comm->CommandType = adCmdStoredProc ;
comm->Parameters->Refresh();
_variant_t recs; comm->Parameters->Item[_variant_t((short)1)]->Value= _variant_t((long)5);
_RecordsetPtr rs = comm->Execute(&recs, &vtMissing,adCmdStoredProc); _variant_t recordcount= comm->Parameters->Item[_variant_t((short)2)]->Value; printf("recordcount = %li\n", (long)recordcount);
return 0;
}
Change the Datasource, User ID and password in the connection string above.
The recordcount variant that the above code returns is of type VT_NULL rather than the number of records that the stored procedure returns.
good luckSteps To Reproduce Behavior
In the SQL Server 7.0 Query Analyzer select the test database Pubs.
Create the following stored procedure. This stored procedure returns a recordset and an out parameter count.if exists (select * from sysobjects where id = object_id(N'[dbo].[GetJobs]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop proc GetJobs
go
create proc GetJobs @id as int, @count as int [out] as
begin
Select @count = Count(*) from jobs where job_id >@id
Select * from jobs where job_id >@id
end
go
Use VC App Wizard to create a new console application and modify the code as follows:#include "stdafx.h"
#include "stdio.h"
#import "C:\PROGRA~1\COMMON~1\System\ado\msado15.dll" no_namespace rename ("EOF", "EOF2") struct InitOle {
InitOle() { ::CoInitialize(NULL); }
~InitOle() { ::CoUninitialize(); }
} _init_InitOle_; int main(int argc, char* argv[])
{
_variant_t varErr((long)0, VT_ERROR);
_CommandPtr comm(__uuidof(Command));
_ConnectionPtr conn(__uuidof(Connection)); _bstr_t connstr="Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=pubs;Data Source=(local)";
conn->Open(connstr, "", "", adConnectUnspecified);
comm->ActiveConnection=conn;
comm->CommandText="GetJobs";
comm->CommandType = adCmdStoredProc ;
comm->Parameters->Refresh();
_variant_t recs; comm->Parameters->Item[_variant_t((short)1)]->Value= _variant_t((long)5);
_RecordsetPtr rs = comm->Execute(&recs, &vtMissing,adCmdStoredProc); _variant_t recordcount= comm->Parameters->Item[_variant_t((short)2)]->Value; printf("recordcount = %li\n", (long)recordcount);
return 0;
}
Change the Datasource, User ID and password in the connection string above.
The recordcount variant that the above code returns is of type VT_NULL rather than the number of records that the stored procedure returns.
解决方案 »
- sql 生成 不重复的 6位随机号码 100条 放在这个表里,并且不和里面的号码重复,怎么写?
- 请问存储过程里的两条默认语句的意义?
- 问题急!在线等:怎么用sql语句查看表结构
- 同一数据库中两表的数据同步(要求用存储过程实现)
- 请教数据更新问题
- 求SQL的写法:2.058^ min(1,365/3015)
- 我如果对数据库中的日期型字段这样操作convert(char(8),日期型字段,120)可不可以,效率如何?
- 应用程序运行速度变的很慢,希望给一些建议,在线等......
- 古怪问题: 为什么用 SQLServer 导入导出工具 从orcale导入SqlServer数据时 报 openrowset 错误
- 如何找到最早用户?想必会者不难。
- 怎样用SQL语句修改sa 的密码?
- 还是CHAR和VARCHAR问题
已经实现用pconn
但是加上输出参数就错了
_ConnectionPtr pConn;
pConn.CreateInstance(_uuidof(Connection));
pConn->Open("Provider = SQLOLEDB.1;Initial Catalog=sql;
Data Source=201.123.133.123","sa" ,"",
adOpenUnspecified);
_CommandPtr Cmd1;
_RecordsetPtr Rs1;
_variant_t Final;
Cmd1.CreateInstance( __uuidof( Command ) );
Cmd1->ActiveConnection = pConn;
Cmd1->CommandText = _bstr_t(L"sp_cal_in");;
Cmd1->CommandType = adCmdStoredProc;
Cmd1->Parameters->Refresh();
Cmd1->Parameters->Item[ _variant_t( (long) 1 ) ]->Value
= _variant_t((LPCTSTR)"345678");
Cmd1->Parameters->Item[ _variant_t( (long) 2 ) ]->Value
= _variant_t((LPCTSTR)"00E04c7713E7");
Cmd1->Parameters->Item[ _variant_t( (long) 3 ) ]->Value
= _variant_t( (long) 1);
Cmd1->Parameters->Item[ _variant_t( (long) 4 ) ]->Value
= _variant_t( (long)0);
Cmd1->Parameters->Item[ _variant_t( (long) 5 ) ]->Value
= _variant_t( (long)121301);
Cmd1->Parameters->Item[ _variant_t( (long) 6 ) ]->Value
= _variant_t( (long)0);
Cmd1->Parameters->Item[ _variant_t( (long) 7 ) ]->Value
= _variant_t((LPCTSTR)"null");
Cmd1->Parameters->Item[ _variant_t( (long) 8 ) ]->Value
= _variant_t((LPCTSTR)"null");
Cmd1->Parameters->Item[ _variant_t( (long) 9 ) ]->Value
= _variant_t((long)index);
Cmd1->Parameters->Item[ _variant_t( (long) 10 )]->Value
= _variant_t((LPCTSTR)ErrInfo);
Cmd1->Execute( &vtEmpty, &vtEmpty2, adCmdUnknown);
我这样执行以后到最后 Execute还是出现了异常
大侠们帮我分析一下吧
是不是我这样写参数不对
最后两个参数是输出参数