473,396 Members | 2,033 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How use newest userid in auto INSERT (2.0)

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?
Jan 13 '06 #1
2 1759
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" <do**@emailme.com> wrote in message
news:eY**************@TK2MSFTNGP10.phx.gbl...
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?

Jan 13 '06 #2
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:OW**************@TK2MSFTNGP11.phx.gbl...
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" <do**@emailme.com> wrote in message
news:eY**************@TK2MSFTNGP10.phx.gbl...
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?


Jan 13 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Nick | last post by:
Is it possible to have multiple auto increments in one column? Say I have two tables... 1. table 'messageboards' with fields ('id' , 'name') 2. table 'messagethreads' with fields ('id' ,...
0
by: Jerry Brenner | last post by:
Our users have potentially dirty legacy data that they need to get into our application. We provide a set of staging tables, which map to our source tables, that the users do their ETL into. ...
2
by: Tom | last post by:
I am trying to store information into a table that has an auto increment field. There is currently no data in the table. Using the code below I cannot insert data into the table. I get an error...
5
by: Phil Latio | last post by:
I have 2 virtually identical tables and wish to move data between them. Basically one table is called "live_table" and the other is named "suspended_table" and the only difference is that the...
1
parshupooja
by: parshupooja | last post by:
Hi , I have asp.net page. I have few fields on page , I am inserting value into this fields which are getting saved into SQL server database. I have additional column into the table(SQL Server)...
0
chumlyumly
by: chumlyumly | last post by:
Hello scripters - OS: Mac OSX Language: PHP w/ MySQL database I've created an insert page where a user inputs his info, which then goes to four different tables in a MySQL database. The...
3
by: Jim | last post by:
Using either EW or VSE2008, I want to have a GridView that will: - Insert the logged in user's UserId from either the User table or the membership table when the user inserts a record. - When the...
4
by: sjohnson1984 | last post by:
Hello all, I have a form which is generated using a database query - the recordset is filled with agent details, login time and the like, and there are as many rows in the table as records in the...
5
by: RomeoX | last post by:
Hi everybody actually I need your help in fixing my code. Actually I have a library system that can be applied in university or any school and I'm stucking in a page that for loan student book. I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.