I need to be able to get the primary key of an nserted row in C#, and so far I'm unsure how. I've put SELECT SCOPE_IDENTITY() into my SQL query, but how do I access this from the SqlDataSource_Inserting method, so I can store it in an auditing table? In my method I only now how to access the parameters (e.Command.Parameters)
EDIT:
My parameters are stored in my ASP.NET file like so (some extracts):
InsertCommand="INSERT INTO [NominalCode] ([VAXCode], [Reference], [CostCentre], [Department], [ReportingCategory]) VALUES (@VAXCode, @Reference, @CostCentre, @Department, @ReportingCategory)"
<InsertParameters>
<asp:ControlParameter ControlID="DetailsView1" Name="VAXCode"
PropertyName="SelectedValue" />
<asp:ControlParameter ControlID="DetailsView1" Name="Reference"
PropertyName="SelectedValue" />
<asp:ControlParameter ControlID="DetailsView1" Name="CostCentre"
PropertyName="SelectedValue" />
<asp:ControlParameter ControlID="DetailsView1" Name="Department"
PropertyName="SelectedValue" />
<asp:ControlParameter ControlID="DetailsView1" Name="ReportingCategory"
PropertyName="SelectedValue" />
</InsertParameters>
And I fill the parameters in C# codebehind
command.Parameters.AddWithValue("@source", "Nominal");
command.Parameters.AddWithValue("@action", "Insert");
command.Parameters.AddWithValue("@item", fields);
command.Parameters.AddWithValue("@userid", name);
command.Parameters.AddWithValue("@timestamp", DateTime.Now);
Thanks