How to session the ID
Ok now that I have insert a new database in my table how can I session the ID that are just insert into the database?
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Iftikar HussainRank #423 · 5.9K reputationPosted Jul 8, 2013, 7:30 AM EDT
First modify your Stored Procedure to include the below line after the insert statement
SELECT @@IDENTITY
Then in your code where you are executing the sql statement to insert the record in your db, there you need to modify write cmd.ExecuteScalar() instead on cmd.ExecuteNonQuery like this
String id=cmd.ExecuteScalar().ToString();
Session["UserId"]=id;
Let me know if you need more information.
Regards,
Iftikar
Tan Kai Kai114 reputationPosted Jul 8, 2013, 5:53 PM EDT
cmd.ExecuteNonQuery like this
String id=cmd.ExecuteScalar().ToString();
Session["UserId"]=id;
Say that
ExecuteScalar: Connection property has not been initialized.
Jignesh TrivediRank #16 · 50.3K reputationPosted Jul 8, 2013, 8:10 PM EDT
hi,
Please refer following link it might help you to resolve your problem
http://msdn.microsoft.com/en-us/library/ks9f57t0.aspx
http://stackoverflow.com/questions/9319532/return-value-from-sql-server-insert-command-using-c-sharp
Riyaz AkhtarRank #2,275 · 619 reputationPosted Jul 8, 2013, 10:54 PM EDT
http://forums.asp.net/t/1893177.aspx/1
mohan raj55 reputationPosted Jul 8, 2013, 11:17 PM EDT
Tan Kai Kai114 reputationPosted Jul 9, 2013, 8:01 AM EDT