Author |
Topic |
swissivan
Starting Member
30 Posts |
Posted - 2013-03-03 : 22:18:22
|
I got two Tables 'Purchase Order' abd 'Purchase Order Products'.I am using c# program to call store procedure.I would like to generate id and insert record for 'Purchase Order' first. Then insert records for 'Purchase Order Products' since it includes the ids generated.If just calling a single store procedure, I can use TRY CATCH and ROLLBACK to make sure updates of two tables in sync. However, I do not know how to pass a list of information (i.e. all records for Purchase Order Product) into a single store procedure.e.g. pass the following list as parameterseach Product include name, qty, amountProductA, 1, $20ProductB, 3, $28...So I assume calling insert product procedure each time for one product, but then it cannot rollback the inserted row of 'Purchase Order' if any errors occur in inserting 'Products'.Is there any practice that can solve my situation so I could make sure all records (Order and Products) will be added or no records will be added and error is known? |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
swissivan
Starting Member
30 Posts |
Posted - 2013-03-03 : 22:37:55
|
quote: Originally posted by visakh16 you're multiple ways to do thisseehttp://vyaskn.tripod.com/passing_arrays_to_stored_procedures.htm------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
Thanks, it is a solution for 2d array.My situation is more complicated as 3d array and I got many fields.ProductA, 1, $20, Adescription, ... etcProductB, 3, $28, Bdescription, ... etc...I need to pass many info for a lot of records, so the total number of values to be passed in store procedure may be more than 100 and which is unknown.Any enhancement or tricks for the solution that can help? thanks, |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-03-03 : 22:42:35
|
what do you mean 3d array? A table has only 2 dimensions- row and column------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
swissivan
Starting Member
30 Posts |
Posted - 2013-03-03 : 22:56:20
|
quote: Originally posted by visakh16 what do you mean 3d array? A table has only 2 dimensions- row and column------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
Thank and sorry I got typing mistake, it is a solution for 1d array.My situation is more complicated as 2d array and I got many fields.ProductA, 1, $20, Adescription, ... etcProductB, 3, $28, Bdescription, ... etc...I need to pass many info for a lot of records, so the total number of values to be passed in store procedure may be more than 100 and which is unknown.Any enhancement or tricks for the solution that can help? thanks, |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-03-03 : 22:59:44
|
tell us your scenario first. i didnt understand whats the issue with methods in posted linkwhatever be number of values you can always use a method like XML to pass them and then use XML functions like nodes, query to shred the data onto the tables.------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
swissivan
Starting Member
30 Posts |
Posted - 2013-03-04 : 05:25:33
|
quote: Originally posted by visakh16 tell us your scenario first. i didnt understand whats the issue with methods in posted linkwhatever be number of values you can always use a method like XML to pass them and then use XML functions like nodes, query to shred the data onto the tables.------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
After more research, xml seems a good direction and I would explore more to see how can it apply to my application.Thanks. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-03-04 : 06:02:35
|
ok...cool... you can do like<Node><Field1></Field1><Field2></Field2>...</Node>------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
|