locked
Iterate array value in Stored Procedure RRS feed

  • Question

  • User-1241097802 posted

    I have one web method in which it contains three parameter

      [System.Web.Services.WebMethod]
            public static void GetSaveData(string iName, string iPath, string[] iData)
            { 
                 //code
            }

    Now i want to insert the iName And iPath in my TABLE 1 with auto increment id. 

    PKId	iName	   iPath
    1       cyx.jpeg   c:\

    Now the iData which is type array contain multiple record. i want to insert this data into TABLE 2 with FK 

    Id   FKID   Name	
    1    1      Data1
    2    1      Data2
    3    1      Data3
    4    1      Data4

    How i can i write STORED PROCEDURE FOR THIS also if TABLE 2 contains error i want to rollback the TABLE 1 value as well

    Saturday, February 8, 2020 7:48 PM

Answers

  • User-17257777 posted

    Hi Programming and Design,

    I think you should first insert the record with name and path into table1, and then you can get the id of the record in table1. Iterate the array to Insert each data  with the previously obtained id into table2.

    Best Regards,

    Jiadong Meng

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, February 10, 2020 7:55 AM