using select scope_identity()


I have  the following insert statemet that  I want to use and return the identity column created by using this. Howerver evenig i used select scope_identity it is not retruning the identity. Any ideas
string LoInsert =("INSERT INTO mms.dbo.user_inf (UserName,PasswordHint,UserAlternateLogin)" +
                     "Select l.lo_login,'Email',l.email_address from INTRANET.dbo.lo_information l where l.email_address='" + (alternateLogin) + "' and '" + (username) + "' = null SELECT SCOPE_IDENTITY()");

thank you so much
Who is Participating?
dstanley9Connect With a Mentor Commented:
Are you sure it's inserting any rows?  You insert clause

"where l.email_address='" + (alternateLogin) + "' and '" + (username) + "' = null"

Would not return any rows since it would be comparing '{username}' = null, which would always be false.
How are you executing the query (ExecuteNonQuery, ExecuteScalar, etc.) ?  Are you expecting a return value or a result set?  
jemigossayeAuthor Commented:
I am executing using executeScalar() exepect like this

userId =Convert.ToInt32(LoCommand.ExecuteScalar());
jemigossayeAuthor Commented:
thank you that was my problem. NO idea what i was thinking
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.