Hi, I have a question please I am using a DetailView to Insert into a SQL Server database. I then want to get the last identity id and use it at the end of url to redirect it to another page. I've done a lot of research and I think I have it right but it is not working...here's my code, please help...
asp.net code:
<asp:SqlDataSource ID="eventDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:RSVPApplicationConnectionString %>"
InsertCommand="INSERT INTO Events(eventName, description, host, eventRegistrationClosed) VALUES (@eventName, @description, '{a53e98e4-0197-4513-be6d-49836e406aaa}', @eventRegistrationClosed); SET @NewID = Scope_Identity()"
SelectCommand="SELECT eventAuid, eventName, description, host, isActive, eventRegistrationClosed
FROM Events
WHERE eventAuid = @eventAuid">
<InsertParameters>
<asp:Parameter Name="eventName" />
<asp:Parameter Name="description" />
<asp:Parameter Name="host" />
<asp:Parameter Name="eventRegistrationClosed" />
<asp:Parameter Direction = "Output" Name="NewId" Type="Int16" />
</InsertParameters>
<SelectParameters>
<asp:QueryStringParameter Name="eventAuid" QueryStringField="eventAuid" />
</SelectParameters>
</asp:SqlDataSource>
then my c# code:
protected void eventDataSource_Inserted(object sender, SqlDataSourceStatusEventArgs e)
{
string newId = e.Command.Parameters["@NewID"].Value.ToString();
Response.Redirect("AddEventOccurrence.aspx?eventAuid=" + newId);
}
Please please tell me what I am doing wrong. I do not understand. The insert works but it will not redirect it to other page. Thank you!!!!