Solved

Insert using a stored procedure

Posted on 2006-06-08
5
281 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
Comment Utility
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 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

743 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now