使用C#将存储过程的结果导出到文本文件中 [英] Exporting the result of stored procedure into text file using C#

查看:73
本文介绍了使用C#将存储过程的结果导出到文本文件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将值从存储过程导出到文本文件,我得到了一个带输入参数的存储过程。在按钮单击事件上,我想通过传递输入值将值导出到文本文件。



存储过程:

How to export the values from Stored procedure to text file , i got a stored procedure with input parameter. On the button click event i wanted to export the values to text file by passing input value.

Stored Procedure:

ALTER PROCEDURE [dbo].[spPOExport]
 @BST_BESTELLUNG INT 
AS
BEGIN
SELECT 
BH.BST_LIEFERANT AS SUPPLIER,
BZ.BDT_REFNUMMER AS ITEM_REF, 
BZ.BDT_ANZ_RESTMENGE AS OUTSTANDING_QTY, 
BZ.BDT_EKP_BESTELLT AS PURCHASE_PRICE, 
BH.BST_WAEHRUNG AS CURRENCY
 FROM BESTHEAD BH
INNER JOIN BESTZEIL BZ ON BH.BST_ORIGNR=BZ.BDT_ORIGNR AND BH.BST_BESTELLUNG=BZ.BDT_BESTELLUNG
WHERE
BST_FILIALE = 150
AND
BST_STATUS IN(1,2) 
AND
BZ.BDT_ANZ_RESTMENGE > 0
AND
BH.BST_BESTELLUNG=@BST_BESTELLUNG
END





我将非常感谢使用c#导出任何帮助。



谢谢



I would appreciate any help in exporting with using c#.

Thanks

推荐答案

所以以正常方式从C#代码调用存储过程,并使用SqlReader阅读。然后只需使用File.Write,File.WriteAllBytes或其他File.WriteXXX方法之一(甚至是FileStream)来保存数据。但由于我们不知道您的数据是什么,或者您希望如何存储它,因此该部分完全取决于您。
So call the stored procedure from your C# code in the normal way, and use an SqlReader to read it. Then just use File.Write, File.WriteAllBytes, or one of the other File.WriteXXX methods (or even a FileStream) to save your data. But since we have no ideas what your data is, or how you want to store it, that part is entirely up to you.


这篇关于使用C#将存储过程的结果导出到文本文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆