C# 如何从 CrystalReport 调用 StoredProcedure?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/552613/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to call StoredProcedure from CrystalReport?
提问by Ahmed Atia
I'd like to call a Stored Procedure from a crystal report and assign retrieved value to a field in report?
我想从水晶报告中调用存储过程并将检索到的值分配给报告中的字段?
Any suggestions?
有什么建议?
采纳答案by Ahmed Atia
To call Stored Procedure from crystal report,
要从水晶报告中调用存储过程,
Set data source of report to Stored Procedure (DataBase Expert Wizard). That procedure must met thses requirement
将报表的数据源设置为存储过程(数据库专家向导)。该程序必须满足这些要求
1- You must create a package that defines the REF CURSOR (type of field that will be retrieved).
1- 您必须创建一个定义 REF CURSOR(将被检索的字段类型)的包。
2- The procedure must have a parameter that is a REF CURSOR type. This is because CR uses this parameter to access and define the result set that the stored procedure returns.
2- 该过程必须具有一个 REF CURSOR 类型的参数。这是因为 CR 使用此参数来访问和定义存储过程返回的结果集。
3- The REF CURSOR parameter must be defined as IN OUT (read/write mode).
3- REF CURSOR 参数必须定义为 IN OUT(读/写模式)。
4- Parameters can only be input (IN) parameters. CR is not designed to work with OUT parameters.
4- 参数只能是输入(IN)参数。CR 并非设计为与 OUT 参数一起使用。
5- The REF CURSOR variable must be opened and assigned its query within the procedure.
5- REF CURSOR 变量必须在过程中打开并分配其查询。
6- The stored procedure can only return one record set. The structure of this record set must not change, based on parameters.
6- 存储过程只能返回一个记录集。根据参数,此记录集的结构不得更改。
7- The stored procedure cannot call another stored procedure.
7- 存储过程不能调用另一个存储过程。
回答by Maksym Gontar
Try Database Expert -> (left tree)Current Connections -> Add Command
尝试数据库专家 ->(左树)当前连接 -> 添加命令
In Add Command To Reportscreen input something like:
在Add Command To Report屏幕输入类似的内容:
EXEC dbo.StoredProcedure (param1, param2 ...)
In the same screen you can specify parameters for this query.
在同一屏幕中,您可以为此查询指定参数。
As a result, new data source, based at the query command, will be created. You can use it as an ordinary data source and place values of fields in the report area.
结果,将创建基于查询命令的新数据源。您可以将其用作普通数据源并将字段的值放置在报表区域中。
回答by dotjoe
Just add it like you would a table or view. Parameters (if any) will be added to your report.
只需像添加表或视图一样添加它即可。参数(如果有)将添加到您的报告中。
回答by Supitchaya
EXEC dbo.StoredProcedure param1, param2 , ...
EXEC dbo.StoredProcedure param1, param2, ...
Not input parenthesis.
不输入括号。