Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. 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#.

Is it possible to implement the SQLDataReader class in order to achieve this functionality i.e. reading from the inserted/deleted tables? Or is there some other class that can accommodate this request?

like image 606
TelJanini Avatar asked May 18 '12 05:05

TelJanini


1 Answers

The inserted/deleted tables are available in the OUTPUT clause of the INSERT statement. You could use the OUTPUT clause in the INSERT in your stored procedure and use SQLDataReader to pick up the result.

like image 102
joshp Avatar answered Nov 09 '22 08:11

joshp