Use a stored procedure to process one-to-multiple data and store process data
Today, Insus. NET shares our experience on how to store one-to-many relationship data during development. In this case, you may encounter that the primary table record and the sub-Table record are stored at the same time, but the sub-table and the master table have a primary foreign key Association.
The following two tables are created, which are associated with the foreign key of the primary key.
Generally, you add the record of Table A in the primary table to obtain the added primary key value, and then add the record of Table B. Or submit at the same time, but the program needs to connect to the database twice to obtain the primary key value, and then insert TableB data.
The following method of Insus. NET is to submit data to the database at a time.
First, the custom table type created in the database is basically the TableB structure:
Create a stored procedure, insert Table A data in the master table, and return the primary key value.
The following stored procedure is referenced by the Program:
In the program, we can create a category:
Frontend uses this category:
Execution result: