Link to home
Start Free TrialLog in
Avatar of TrialUser
TrialUserFlag for Afghanistan

asked on

ado.net code to get the id of the column inserted using stored procedure

In my stored procedure I insert a record. After the insert my stored procedure does soemthing like :
select @userid = SCOPE_IDENTITY()
select @userid

Using ado.net code how can i get the value of @userid. please help

c#.net code:

SqlCommand cmd = new SqlCommand("user_ins");
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@userName", username
           cmd.Parameters.AddWithValue("@End_dt", enddt);

            using (SqlConnection conn = new SqlConnection(ConnectionString))
            {
                conn.Open();
                cmd.Connection = conn;
                cmd.ExecuteNonQuery();
            }
ASKER CERTIFIED SOLUTION
Avatar of Dale Burrell
Dale Burrell
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of TrialUser

ASKER

perfect.