Clicky

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();
            }

asked 12/14/2011 11:35

TrialUser's gravatar image

TrialUser ♦♦


2 Answers:
Object MyValue = cmd. ExecuteScalar();
String TempId = null;
if (MyValue != null && MyValue != System.DBNull.Value) TempId = (String)MyValue;
link

answered

dale_burrell's gravatar image

dale_burrell

perfect.
link

answered 2011-12-14 at 19:44:34

TrialUser's gravatar image

TrialUser

Your answer
[hide preview]

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Tags:

Asked: 12/14/2011 11:35

Seen: 313 times

Last updated: 12/14/2011 12:11