[英]Using a SQL DataReader to capture inserted or deleted values
I'm currently calling a stored procedure from a .net application that inserts records into the database. 我正在从.net应用程序调用存储过程,该过程将记录插入数据库。 However, I need to get a list of the records that I've just inserted successfully.
但是,我需要获取我刚刚成功插入的记录列表。
I know that I could return the inserted rows from the stored procedure directly, but I was hoping there was a way to do this programatically in C#. 我知道我可以直接从存储过程返回插入的行,但我希望有一种方法可以在C#中以编程方式执行此操作。
Is it possible to implement the SQLDataReader class in order to achieve this functionality ie reading from the inserted/deleted tables? 是否可以实现SQLDataReader类以实现此功能,即从插入/删除的表中读取? Or is there some other class that can accommodate this request?
或者是否有其他类可以容纳此请求?
The inserted/deleted tables are available in the OUTPUT clause of the INSERT statement. 插入/删除的表在INSERT语句的OUTPUT子句中可用。 You could use the OUTPUT clause in the INSERT in your stored procedure and use SQLDataReader to pick up the result.
您可以在存储过程的INSERT中使用OUTPUT子句,并使用SQLDataReader来获取结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.