如何在VC.net中调用带输出参数的存贮过程.sql?

wxshzf 2003-11-06 10:36:02
我的存贮过程如下:
CREATE PROCEDURE [dbo].[GetCount]
@RstCount int output,
@TblName nvarchar(100)
as
declare @TmpStr nvarchar(1000)
Set @TmpStr=N'select @RstCount=count(*) from '+ @TblName
exec sp_executesql @TmpStr,N'@RstCount int output',@RstCount output
return @RstCount
GO
在查询窗口调用如下
declare @RecCount int
exec GetCount @RecCount output,'yuanqijian'/*元器件表*/
print @RecCount
成功,而我在VC.Net中调用时总出错,代码如下:
int MyCount=0;
CString SqlStr="exec GetCount MyCount output,'yuanqijian'";
m_SqlDB.ExecuteSQL(SqlStr);//m_SqlDB,为数据库对象,已成功连接上数据源
int a=MyCount;
请问SqlStr该如何写?
...全文
91 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
wxshzf 2003-11-06
  • 打赏
  • 举报
回复
感谢pengdali(大力 V3.0),请问如果在vc++6.0中该如何调用呢?
pengdali 2003-11-06
  • 打赏
  • 举报
回复
1、
CREATE PROCEDURE [dbo].[GetCount]
@RstCount int output,
@TblName nvarchar(100),
as
declare @TmpStr nvarchar(1000)
Set @TmpStr=N'select @RstCount=count(*) from '+ @TblName
exec sp_executesql @TmpStr,N'@RstCount int output',@RstCount output
GO



2、如:
below is from MSDN,you can find a lot of technical article in MSDN if you search"stored procedure and VC"
good luck

Steps 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.
代码下载链接: https://pan.quark.cn/s/b27638adc362 在工业自动化监控领域,WinCC 被视为一种常用的可视化软件,其功能在于构建人机界面(HMI)以及SCADA系统。本资料将阐释在WinCC环境下如何构建一个展现管道流体流动的动态效果,此功能主要通过C动作脚本来完成。在此过程,我们需要构建两个矩形,分别标记为 rec1 和 rec2。这两个矩形的高度相等,但 rec1 的宽度要小于 rec2。在具体实施时,rec1 将作为展示流体运动的可见单元,而 rec2 则作为辅助元素,尽管其“显示”属性被设为关闭,但在程序执行期间,其属性参数对流体动画的表现起着决定性作用,因为 rec2 与 rec1 的宽度差将决定流体每次移动的长度。 随后,我们需要将 rec1 和 rec2 整合为一个自定义对象。在自定义对象的属性配置,应包含 rec1.Left、rec1.Width、rec1.Visible 和 rec2.Width 这些核心属性。这些属性将有助于在C脚本精确控制对象的位置和可见状态,以达成流体运动的视觉效果。同时,用户可根据实际需求增加其他属性,以增强自定义对象的功能性。 在自定义对象的C脚本部分,我们设定了一个周期为“250ms”的触发器。该脚本的核心职责是计算并更新流体块的位置。借助 GetPropBOOL、GetPropWord 和 GetLeft 函数,我们可以获取对象的当前状态,涵盖其可见性、位置及宽度等参数。在循环操作,流体块(rec1)将向右移动 rec2 - rec1 的距离,一旦流体块移出显示范围(即 rec1 的右边界达到或超过 rec2 的左边界),它将重新回到起始位置,从而形成流体持续流动的模...

34,875

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧