| |

VerySource

 Forgot password?
 Register
Search
View: 4317|Reply: 34

Stored procedure receives multiple parameter problems Master invited

[Copy link]

1

Threads

10

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

Post time: 2020-1-30 18:40:02
| Show all posts |Read mode
I used DataList to make a list of pictures. I want to add the selected pictures to the album.
for (int i = 0; i <DataList1.Items.Count; i ++) // Cycle the collection of DataList1
{
    if (xx.checked) // If the picture is selected
      {
         int id = e.Item.FindControl ("label1") // Remove the ID of this image
         int classid = 1 // album id
         ................. / Execute the stored procedure
      }
}

This is my implementation method. This loop judges which picture is selected. If selected, the picture id and album ID are passed to the stored procedure and executed once. If 10 are selected, this loop executes the stored procedure 10 times, so that 10 pictures are modified.
What can I do to execute the stored procedure once to modify these 10 pieces of data. What should be written in the stored procedure

Heroes had better post some code. My little rookie
Reply

Use magic Report

1

Threads

10

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

 Author| Post time: 2020-3-7 18:15:01
| Show all posts
I wonder if the stored procedure can receive a set of data? That is, I took out the selected IDs in the previous paragraph and passed them to the stored procedure once, so that I did not need to execute the stored procedure 10 times.
Reply

Use magic Report

0

Threads

8

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

Post time: 2020-3-7 20:00:01
| Show all posts
With a parameter
Separate items with special characters
Split each item in the storage process
Reply

Use magic Report

0

Threads

322

Posts

115.00

Credits

Newbie

Rank: 1

Credits
115.00

 China

Post time: 2020-3-8 12:30:02
| Show all posts
Stored procedures can receive multiple parameters, but the number of parameters is fixed.

There is another way.

Pass a string. It is then split during the stored procedure. Then generate sql
Then exec this sql.
Reply

Use magic Report

0

Threads

119

Posts

67.00

Credits

Newbie

Rank: 1

Credits
67.00

 China

Post time: 2020-3-8 14:00:02
| Show all posts
Split string!
Reply

Use magic Report

0

Threads

322

Posts

115.00

Credits

Newbie

Rank: 1

Credits
115.00

 China

Post time: 2020-3-8 14:15:01
| Show all posts
Of course, the simple way is to generate SQL in the program instead of using stored procedures.
Reply

Use magic Report

0

Threads

4

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-3-8 14:45:01
| Show all posts
create or replace type mytable as table of varchar2 (1000);

Call mytable
Reply

Use magic Report

0

Threads

6

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-3-8 19:30:01
| Show all posts
CREATE PROCEDURE Test
    @idString NVARCHAR (1000)
AS
    DECLARE @sql NVARCHAR (2000)

    SET @sql = "UPDATE Images SET album = 1 WHERE (ImageID IN ('" + @idStrings + "')"

    exec @sql


@idStrings is a combination of the above from your code in the form:
    imgeid1, imageid2, imageid3
Reply

Use magic Report

0

Threads

14

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

Post time: 2020-3-9 13:45:01
| Show all posts
If the number of incoming strings is large and the combined length of the combined string exceeds 4000, consider using Xml
Reply

Use magic Report

1

Threads

8

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 Unknown

Post time: 2020-3-9 17:00:02
| Show all posts
Upstairs ok
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list