Solved

Insert using a stored procedure

Posted on 2006-06-08
5
285 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 500 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
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.…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

726 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