Introduction
In this article, I will explain how to insert multiple rows using a user-defined table type. Here I explain step-by-step:
Step 1. Create UI Design to Add Row and Display Rows on the .aspx page
First, I am creating a UI design to add the employee's name and salary. It has a button that, when clicked, creates a row in the Data Table added. See:
Step 2. Add required namespaces on aspx.cs page; they are.
Step 3. Create a Data Table
I created a Data Table that contains dynamically added data rows. This data table is used to pass data to the user-defined table type. This table should be declared globally to be used in all methods.
Step 4. Create Columns and Add on the Page Load
First, I create columns for the Data Table in the page load event. These columns are defined as per a user-defined table type; in other words, in a data table, we define several columns as in a user-defined table type.
Here it is called the page load method because we want to create the table structure in the page load only once. See:
Step 5. Add Row and Display
Here I am adding a new row in the Data Table, and that data row is shown in a grid view when the Add button is clicked.
Step 6. Create a User-Defined Table Type
In the database, I create a user-defined Table type with two columns to store the employee's name and salary.
![Image1.jpg]()
Step 7. Create a store procedure
Create a stored procedure that has a user-defined table type as a parameter. This parameter contains all data passed by the client.
![Image2.jpg]()
Step 8. Add a Button in the UI to Insert all rows(.aspx page)
I create a button that has a click event. On that event, we add all the rows in the database table.
Step 9. Insert All Rows
Here I insert all rows on button click. I pass the data table using a user-defined table type with all rows of the Data Table, and it is used as a SQL parameter.
Output
![Image3.jpg]()