| |

VerySource

 Forgot password?
 Register
Search
Author: mgs_pexp

Stored procedure receives multiple parameter problems Master invited

[Copy link]

1

Threads

8

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 Brazil

Post time: 2020-3-9 17:30:01
| Show all posts
wwhhoon

 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

1

Threads

10

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

 Author| Post time: 2020-3-15 13:30:02
| Show all posts
Can you be more detailed upstairs ~~~
Reply

Use magic Report

1

Threads

10

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

 Author| Post time: 2020-3-18 14:45:01
| Show all posts
Let's put it this way: I combined the selected image IDs into a string in the background of the page, separated by commas, such as: "1,2,3,4,6,7,8,"
This is passed to the stored procedure. The stored procedure splits the string of IDs, and then the name field is "tested" based on these IDs.
How to write specific stored procedures

 I am a rookie! !! !! !! Heroes don't just talk about ideas and actual code! !! !!
Reply

Use magic Report

1

Threads

10

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

 Author| Post time: 2020-3-19 15:30:01
| Show all posts
Continue to wait for the master
Reply

Use magic Report

0

Threads

8

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

Post time: 2020-3-21 09:45:01
| Show all posts
To update uncertain data content with stored procedures, it is best to use DataAdpater + DataSet
Reply

Use magic Report

0

Threads

8

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

Post time: 2020-3-21 21:15:02
| Show all posts
SqlDataAdapter catDA = new SqlDataAdapter ("SELECT CategoryID, CategoryName FROM Categories", nwindConn);
catDA.UpdateCommand = new SqlCommand ("UPDATE Categories SET CategoryName = @CategoryName" +
                                     "WHERE CategoryID = @CategoryID", nwindConn);

catDA.UpdateCommand.Parameters.Add ("@ CategoryName", SqlDbType.NVarChar, 15, "CategoryName");

SqlParameter workParm = catDA.UpdateCommand.Parameters.Add ("@ CategoryID", SqlDbType.Int);
workParm.SourceColumn = "CategoryID";
workParm.SourceVersion = DataRowVersion.Original;

DataSet catDS = new DataSet ();
catDA.Fill (catDS, "Categories");

DataRow cRow = catDS.Tables ["Categories"]. Rows [0];
cRow ["CategoryName"] = "New Category"; // Here changed one line of data, you can modify multiple lines by loop


catDA.Update (catDS);

ps: copied from above
ms-help: //MS.MSDNQTR.2003FEB.2052/cpguide/html/cpconupdatingdatabasewithdataadapterdataset.htm
Reply

Use magic Report

1

Threads

10

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

 Author| Post time: 2020-3-22 19:45:02
| Show all posts
This method is too good. Is there any other way
Reply

Use magic Report

0

Threads

5

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-3-23 12:30:01
| Show all posts
----
Let's put it this way: I combined the selected image IDs into a string in the background of the page, separated by commas, such as: "1,2,3,4,6,7,8,"
This is passed to the stored procedure. The stored procedure splits the string of IDs, and then the name field is "tested" based on these IDs.

.......

The brother upstairs has given:

wwhhoon

 CREATE PROCEDURE Test
    @idString NVARCHAR (1000) // If its value is 1,2,3,4,6,7,8
AS
    DECLARE @sql NVARCHAR (2000)

    SET @sql = "UPDATE Images SET [Name] = 'Test' WHERE (ID IN ('" + @idStrings + "')"

    exec @sql


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

Use magic Report

1

Threads

10

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

 Author| Post time: 2020-3-23 22:45:01
| Show all posts
This is not easy to make ~~~~ There is a problem.
Which big brother should check it and change the error 1! !!
Reply

Use magic Report

0

Threads

9

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

Post time: 2020-3-26 18:30:01
| Show all posts
Modify the stored procedure. Let the parameter received by the stored procedure be a string separated by ",". Then go to the stored procedure for processing.

For example: "1,2,3,4,5,6" Then you choose ten, which is 10 strings with ID numbers separated by ",".

There is no need to think about executing it a few times.
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