Insert and Update in SQL Using User-Defined Table Type in C#
APPLIES TO: SQL Server and Azure SQL Database.
Let Start with [ SQL]
For creating a user-defined table type in SQL here is the procedure:

  1. First create a user-defined table type by selecting in Object Explorer.
  2. Inside that select your database.After selecting it just expand it.
  3. Inside that select the Programmability Folder. After selecting it just expand it.
  4. You will see a folder with Name Types.
  5. Just select and expand it and you will see a user-defined table type.
  6. Just right-click on the folder and select “New User-Defined Table Type…”.

Here is a Snapshot.

User Defined Table Types SQLServer

After selecting you will see this view.

Create User defined Table Type
Create User defined Table Type

Then I created a Table (SQL Table).

Here I created a user-defined type.

Here in this Stored Procedure I used “User_Define_Table_Type”.

Let us Start with C# Here I am passing a Datatable to SQL. Here is the connection String.