Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > How use newest userid in auto INSERT (2.0)

Reply
Thread Tools

How use newest userid in auto INSERT (2.0)

 
 
VB Programmer
Guest
Posts: n/a
 
      01-13-2006
I have a table called 'MyUsers'. Some fields are as follows:
UserId (p key to tie it to aspnet_Users), MyAddress, MyCity, MyState, etc...

After I do a Membership.CreateUser to add the new member to aspnet_Users I
want to run the Insert command from my SqlDataSource, using the new UserId.
(I guess it's ProviderUserKey?)

The Insert command for my SqlDataSource is stated as:
InsertCommand="INSERT INTO [MyUsers] ([UserId], [FirstName], [LastName],
[MyPhone], [MyAddress], [MyCity], [MyState], [MyZip], [ExpYears],
[ExpSponsor], [ExpSponsorUrl], [ExpClass], [ExpWebsiteUrl], [ExpComments])
VALUES (@UserId, @FirstName, @LastName, @MyPhone, @MyAddress, @MyCity,
@MyState, @MyZip, @ExpYears, @ExpSponsor, @ExpSponsorUrl, @ExpClass,
@ExpWebsiteUrl, @ExpComments)"

I want to use the NEW UserId for the Insert command. Any ideas?


 
Reply With Quote
 
 
 
 
S. Justin Gengo [MCP]
Guest
Posts: n/a
 
      01-13-2006
VB Programmer,

In your stored procedure you use @@Identity to get the just created id. You
may then use that new id in a new statement right there in the same stored
procedure or return it. To return it you would do something like:

@Name As nvarchar(100),
@NewId int output

INSERT COMMAND HERE;

SET @NewId = SELECT @@Identity

RETURN

In .NET 2.0 you also need to specify the output parameter as part of your
insert statement.

Here's an article that shows one way of doing this:
http://msdn2.microsoft.com/en-us/lib....inserted.aspx



--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"VB Programmer" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I have a table called 'MyUsers'. Some fields are as follows:
> UserId (p key to tie it to aspnet_Users), MyAddress, MyCity, MyState,
> etc...
>
> After I do a Membership.CreateUser to add the new member to aspnet_Users I
> want to run the Insert command from my SqlDataSource, using the new
> UserId. (I guess it's ProviderUserKey?)
>
> The Insert command for my SqlDataSource is stated as:
> InsertCommand="INSERT INTO [MyUsers] ([UserId], [FirstName], [LastName],
> [MyPhone], [MyAddress], [MyCity], [MyState], [MyZip], [ExpYears],
> [ExpSponsor], [ExpSponsorUrl], [ExpClass], [ExpWebsiteUrl], [ExpComments])
> VALUES (@UserId, @FirstName, @LastName, @MyPhone, @MyAddress, @MyCity,
> @MyState, @MyZip, @ExpYears, @ExpSponsor, @ExpSponsorUrl, @ExpClass,
> @ExpWebsiteUrl, @ExpComments)"
>
> I want to use the NEW UserId for the Insert command. Any ideas?
>



 
Reply With Quote
 
 
 
 
VB Programmer
Guest
Posts: n/a
 
      01-13-2006
Thanks. Is there any example that shows how to do something like this (the
simplest way) in ASP.NET 2.0...

1. Simple CreateAddress webform with several textboxes (txtAddress, txtCity,
txtState), 1 save button.
2. Click Save button and the data is inserted into the Addresses table.

I know how to do it with ADO.NET code, but how can I do it codeless, using I
suppose the SqlDataSource?

Thanks.

"S. Justin Gengo [MCP]" <justin@[no_spam_please]aboutfortunate.com> wrote in
message news:(E-Mail Removed)...
> VB Programmer,
>
> In your stored procedure you use @@Identity to get the just created id.
> You may then use that new id in a new statement right there in the same
> stored procedure or return it. To return it you would do something like:
>
> @Name As nvarchar(100),
> @NewId int output
>
> INSERT COMMAND HERE;
>
> SET @NewId = SELECT @@Identity
>
> RETURN
>
> In .NET 2.0 you also need to specify the output parameter as part of your
> insert statement.
>
> Here's an article that shows one way of doing this:
> http://msdn2.microsoft.com/en-us/lib....inserted.aspx
>
>
>
> --
> Sincerely,
>
> S. Justin Gengo, MCP
> Web Developer / Programmer
>
> www.aboutfortunate.com
>
> "Out of chaos comes order."
> Nietzsche
> "VB Programmer" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>>I have a table called 'MyUsers'. Some fields are as follows:
>> UserId (p key to tie it to aspnet_Users), MyAddress, MyCity, MyState,
>> etc...
>>
>> After I do a Membership.CreateUser to add the new member to aspnet_Users
>> I want to run the Insert command from my SqlDataSource, using the new
>> UserId. (I guess it's ProviderUserKey?)
>>
>> The Insert command for my SqlDataSource is stated as:
>> InsertCommand="INSERT INTO [MyUsers] ([UserId], [FirstName], [LastName],
>> [MyPhone], [MyAddress], [MyCity], [MyState], [MyZip], [ExpYears],
>> [ExpSponsor], [ExpSponsorUrl], [ExpClass], [ExpWebsiteUrl],
>> [ExpComments]) VALUES (@UserId, @FirstName, @LastName, @MyPhone,
>> @MyAddress, @MyCity, @MyState, @MyZip, @ExpYears, @ExpSponsor,
>> @ExpSponsorUrl, @ExpClass, @ExpWebsiteUrl, @ExpComments)"
>>
>> I want to use the NEW UserId for the Insert command. Any ideas?
>>

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Auto Shipping Auto Shipping Scheduling:car moving auto transport linkswanted ASP .Net 1 11-22-2013 07:02 AM
how do i insert userid in formview Jim ASP .Net 6 01-16-2008 06:46 PM
SessionID -> UserId Insert and View Jim ASP .Net 3 12-03-2007 11:05 PM



Advertisments