Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Insert using a stored procedure

Posted on 2006-06-08
5
Medium Priority
?
289 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 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

636 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