I want to receive all output primary key from this insert command using C# ADO.Net.
I run this in SQL Server 2012 Studio and I saw the result table with all of the values, so is it possible to get that table from C#?
INSERT INTO dbo.Suspension
(pallet_position, processing_pallet_pkey, datetime_created, datetime_updated,
created_by, updated_by)
OUTPUT INSERTED.pkey VALUES
(1, 2, '20141013 16:27:25.000', '20141013 16:27:25.000', 2, 2),
(2, 2, '20141013 16:27:25.000', '20141013 16:27:25.000', 2, 2),
(3, 2, '20141013 16:27:25.000', '20141013 16:27:25.000', 2, 2),
(4, 2, '20141013 16:27:25.000', '20141013 16:27:25.000', 2, 2);
What I have tried in C# ADO.NET. But DataTable didn't get any value from the insertedOutput.
SqlCommand cmd = new SqlCommand(insertQuery, this.conn);
var insertedOutput = cmd.ExecuteReader();
DataTable dt = new DataTable();
dt.Load(insertedOutput); // something wrong here
Noted that I copied the SQL code from the debugger. It work fine. (not sure where the 'this.' come from but it didn't cause any issues)
In the debugger, there are results from cmd.ExecuteReader() in insertedOutput, but I can't copy those result from dt (a DataTable variable).
// this cause an error.<=== what does the error say?this.created_byetc) - can you confirm what is happening there?