Solved

using select scope_identity()

Posted on 2006-06-13
4
340 Views
Last Modified: 2010-04-16
Hello,

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
0
Comment
Question by:jemigossaye
  • 2
  • 2
4 Comments
 
LVL 25

Expert Comment

by:dstanley9
ID: 16896973
How are you executing the query (ExecuteNonQuery, ExecuteScalar, etc.) ?  Are you expecting a return value or a result set?  
0
 

Author Comment

by:jemigossaye
ID: 16897046
I am executing using executeScalar() exepect like this

userId =Convert.ToInt32(LoCommand.ExecuteScalar());
0
 
LVL 25

Accepted Solution

by:
dstanley9 earned 250 total points
ID: 16897226
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.
0
 

Author Comment

by:jemigossaye
ID: 16897274
thank you that was my problem. NO idea what i was thinking
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
creating a flowchart from an algorithm 5 30
Installing IIS after Visual Studio 2015 Community Edition 5 46
Error on link 14 36
Entity Framework 7 28
Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now