Last post Feb 07, 2012 12:30 AM by fredd_and
Feb 06, 2012 02:47 AM|fredd_and|LINK
Hi, i am trying to get the UserId of just inserted member from Userprofile table in webmatrix membership startersite template. Using C#
i try to use Scope Identity SQL in Account/register.cshtml, but dont know idea how to do it in webmatrix
any suggest how to do it? so i can take the UserId for new registed user.
Feb 06, 2012 02:54 AM|sreejukg|LINK
Feb 06, 2012 03:42 AM|fredd_and|LINK
i read that blog before, and apply it to my asp.net web form,
in web matrix i can not get the value,
any sample in web matrix?
Feb 06, 2012 03:54 AM|nilsan|LINK
Please check this
Feb 06, 2012 04:09 AM|vijay_myl|LINK
Refer the below link ..
Feb 06, 2012 07:06 AM|Mikesdotnetting|LINK
There's a method on the Database helper: GetLastInsertId(). That will do what you want:
db.Execute("INSERT INTO table1 (col1, col2, col3) VALUES (@0,@1,@2)", param1, param2, param3);
var Id = db.GetLastInsertId();
It uses @@IDENTITY rather than SCOPE_IDENTITY because it has to support SQL Compact as well as SQL Server. So long as you don't have any triggers on your table, you should be fine with that.
If you do need to use SCOPE_IDENTITY for any compelling reason, you will have to use plain ADO.NET as in my article that sreejukg linked to.
Feb 07, 2012 12:30 AM|fredd_and|LINK
Thank you Mikes, i read this link before read your answer from there.
i just realise there is "GetLastInsertedId" class for webmatrix.