I'm trying to retrieve SCOPE_IDENTITY() and place it in a parameter I can access in codebehind. My .aspx:
<asp:sqldatasource
id="SqlDataSource1"
runat="server"
connectionstring="<%$ ConnectionStrings:myString %>"
insertcommand="INSERT INTO [CountyHelp](County,City)
VALUES (@County,@City) ;SELECT @Id = SCOPE_IDENTITY()">
<insertparameters>
<asp:formparameter name="County" formfield="County" />
<asp:formparameter name="City" formfield="City" />
<asp:parameter Direction="Output" Name="Id" Type="Int32" />
</insertparameters>
Then access it in this code behind:
protected void btn_send_Click(object sender, SqlDataSourceStatusEventArgs e)
{
string sID = e.Command.Parameters["@Id"].Value.ToString();
SqlDataSource1.Insert();
Response.Redirect("documentsnew.aspx?id=" + sID);
}
Maybe it is my button code is not sending the parameter value:
<asp:button
id="Button1"
runat="server"
text="Add Help"
onclick="btn_send_Click"
/>
SqlDataSourceStatusEventArgsfor a button click event.