Use a stored procedure to process one-to-multiple data and store process data

Source: Internet
Author: User

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:

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.