?
Solved

Insert using a stored procedure

Posted on 2006-06-08
5
Medium Priority
?
292 Views
Last Modified: 2012-05-05
Hello,

In my ASP.net Page I have a form for creating users. Below are the fields on the form:

First Name Textbox
Last Name  Textbox
User Id Textbox
Password Textbox
DOB Textbox
Locations Dropdown with multipleselect option

Submit Button

Except Locations all others are textboxes. Locations is a ListBox with SelectionMode=Multiple.

I have two tables User_Master and User_Location
What actually should happen is when the user hits submit First Name,Last Name, User Id, Password, DOB should get inserted into User_Master and the Primarykey(id) and the selected Locations ids  should get inserted into user_location table.

Can this be done with just one stored procedure. If yes, As Locations is multiple select option how can I pass the values to the stored procedure??

0
Comment
Question by:sureshraina
  • 2
  • 2
5 Comments
 
LVL 5

Expert Comment

by:Jojo1771
ID: 16867115
Could this be done. Maybe. Should it? -No

It would be  alot better if you  created 2 sp's one for the insert into master and one for location.

ie


Insert Master --Call SP to insert and have it  return the PK by doing  Select @@Identity as PK in your SP
Then loop thru your ddl
for each item as bah in list of ddl.items
Insert Loc(pass the pk from 1st SP if needed)--2nd SP
next

This is how I would do it.
0
 
LVL 15

Accepted Solution

by:
GavinMannion earned 1500 total points
ID: 16867446
I would agree with Jojo1771, currently with SQL 2000 you cannot pass through complex datatypes like arrays.

So an ugly (and I mean very UGLY) hack would be to add 20 other params to the first storeprocedure to hold possible selected locations. Else you should do it Jojo1771's way.

The ugly hack would add absolutely no value and I would highly recommend against it.
0
 
LVL 2

Expert Comment

by:SKumar_1981
ID: 16868121
Try this
when u inserted in to master table write  a trigger in the master table to insert in to the detail table,

the trigger is

CREATE TRIGGER trig_insert ON master table name
FOR   insert
as

IF inserted(Location)
BEGIN
      Insert into  detailtablename
            lacation = insereted.location
            FROM INSERTED
            END

regards,
skumar
0
 
LVL 2

Expert Comment

by:SKumar_1981
ID: 16868129
Try this
when u inserted in to master table write  a trigger in the master table to insert in to the detail table,

the trigger is

CREATE TRIGGER trig_insert ON master table name
FOR   insert
as

IF inserted(Location)
BEGIN
     Insert into  detailtablename(location) values insereted.location
FROM INSERTED
          END

regards,
skumar
0
 
LVL 15

Expert Comment

by:GavinMannion
ID: 16868232
The trigger would insert as you said, but I think the main question is how do you send through 5 locations with the same stored procedure? Remembering that sometimes it might only be 1 location and other times 20 locations.

I think this will have to be done with 2 sp's
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month15 days, 12 hours left to enroll

850 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