June 30, 2005 at 10:00 am
I have an asp.net vb page with 214 text boxes. I need to save the data from the textboxes to a table. The table has the following rows.
-ID
-User_ID
-Skill_ID
-Skill_Rank
The data in the table looks like this
-ID 78 (autogenerated number)
-User_ID 209756
-Skill_ID 95 (there is another table that this number corresponds to)
-Skill_Rank 5 (1-5 number from the textboxes on my asp.net page)
When the user clicks on the save button I need it to write the User_ID, Skill_ID and the Skill_Rank to the table for every textbox that has a value in it. So I would have multiple User_IDs in the table for each Skill_ID.
I have built the asp.net page with all the textboxes so I know how to pass the Skill_Rank value, but I am not sure how to link the Skill_ID with the Skill_Rank
I am stumped on this.
June 30, 2005 at 10:12 am
A picture of the webpage could be usefull here.
The proc would be very simple :
Insert into dbo.tablename (User_ID, Skill_ID, Skill_Rank) values (@UserId, @SkillId, @SkillRank)
Now you just have to figure out how to pass that information in reference to the design. But I can't help you much with that as I don't know the system.
June 30, 2005 at 10:36 am
I tried doing my stored procedure the same way you did. I tested it with two text boxes.
cmdSave.Parameters.Add("@test", TextBox1.Text)
cmdSave.Parameters.Add("@test", TextBox2.Text)
but I am given this message
Procedure or function Test has too many arguments specified.
I don't see a way to attach screen shot?
June 30, 2005 at 10:38 am
Can we see the proc code and the full asp code?
June 30, 2005 at 10:40 am
Please post the stored procedure you have created.
June 30, 2005 at 10:44 am
(
@UserID INT,
@test INT
)
AS
INSERT dbo.MySurvey_Marketing_Skills_User(User_ID, Skill_Rank, Skill_ID )
Values (@UserID, @Test, 97)
I hand keyed the 97 value because I am not sure how that will work on the asp.net page to pass on.
If IsValid Then
cmdSave = New SqlCommand("Test", GlobalConnection)
cmdSave.CommandType = CommandType.StoredProcedure
parmReturnValue = cmdSave.Parameters.Add("RETURN_VALUE", SqlDbType.Int)
parmReturnValue.Direction = ParameterDirection.ReturnValue
cmdSave.Parameters.Add("@UserID", lvUserID)
cmdSave.Parameters.Add("@test", TextBox1.Text)
cmdSave.Parameters.Add("@test", TextBox2.Text)
GlobalConnection.Open()
cmdSave.ExecuteNonQuery()
GlobalConnection.Close()
June 30, 2005 at 10:50 am
Right here your adding the @test-2 parameter to your cmdsave object twice. The stored procedure only has 1 @test-2 Parameter.
cmdSave.Parameters.Add("@test", TextBox1.Text)
cmdSave.Parameters.Add("@test", TextBox2.Text)
Are you wanting to insert 2 records, or one?
Remove the second parameters.add, and execute the method once for each textbox.
June 30, 2005 at 11:03 am
There are 214 text boxes on the page.
Let's say I enter values into 5 of the text boxes, then I will need to enter those 5 values in the database
My results would look like this
-ID 75
-User_ID 209756
-Skill_ID 95
-Skill_Rank 3
-ID 76
-User_ID 209756
-Skill_ID 65
-Skill_Rank 1
-ID 77
-User_ID 209756
-Skill_ID 35
-Skill_Rank 2
and so on
June 30, 2005 at 11:27 am
You'll have to call the sp one time for each skill/user.
June 30, 2005 at 11:31 am
So then on my asp.net page I can just test to see if the value entered into the textbox is greater than 1 and then fire the sp based on that? Is this the most efficient way of doing it?
June 30, 2005 at 11:35 am
Not exactly. I'd probabely record all the sp calls in a string, then execute the string. I'll save a lot of network traffic that way.
June 30, 2005 at 11:43 am
I have never done that before. Can you give me some advice on where to begin?
June 30, 2005 at 11:52 am
The code to execute the sp one time will be :
Exec dbo.SpName Param1, param2, param3
Now you just have to concatenate that for each line you need to add skills. Then execute that satement.
the final statement may look something like this :
Exec dbo.SpName 1, 3, 67
Exec dbo.SpName 2, 4, 56
Exec dbo.SpName 3, 2, 43
June 30, 2005 at 1:40 pm
OR:
INSERT dbo.MySurvey_Marketing_Skills_User(User_ID, Skill_Rank, Skill_ID )
select 1, 3, 67
union all select 2, 4, 56
union all select 3, 2, 43
* Noel
Viewing 15 posts - 1 through 15 (of 24 total)
You must be logged in to reply to this topic. Login to reply