You can do some of this visually but it is hard to show that here.
In the INSERT command add a select statement to select the SCOPE_IDENTITY().
Be sure to put a semi colon after the INSERT statement.
InsertCommand="INSERT INTO Employees(LastName, FirstName) VALUES (@LastName, @FirstName);
SELECT @EmpID = SCOPE_IDENTITY()"
Define an OUTPUT parameter for the SQLDatasource.
You can change the InsertQuery property for the SQLDataSource to do this part visually.
<InsertParameters>
<asp:Parameter Name="EmpID" Direction="Output" Type="Int32" DefaultValue="0" />
</InsertParameters>
In the SqlDataSource1_Inserted event......
Protected Sub SqlDataSource1_Inserted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceStatusEvent Args) Handles SqlDataSource1.Inserted
Dim intID As Integer
intID = Convert.ToInt32(e.Command.Parameters("@EmpID").Val ue)
End Sub
|