Many times we come across a situation where we need to pass a table to stored procedure from C# code. In such scenarios what we can do is either loop through table and send rows one by one or we can directly pass the full table to the procedure. Passing rows one by one may be inefficient as we have to iterate through rows and call procedure again and again.
SQL Server provides us an efficient way of doing the same using 'User Defined Types' So for passing a table valued parameter to a stored procedure we need to create a user defined table type that will have same columns that we want to pass to the table. Click Database Node > Programmability > Types, then User-Defined Table Types. Now we create a table which will be filled by stored procedure.
SQL Server provides us an efficient way of doing the same using 'User Defined Types' So for passing a table valued parameter to a stored procedure we need to create a user defined table type that will have same columns that we want to pass to the table. Click Database Node > Programmability > Types, then User-Defined Table Types. Now we create a table which will be filled by stored procedure.
- CREATE TABLE [dbo].[Employee](
- [Emp_ID] [int] IDENTITY(1,1) NOT NULL,
- [Emp_name] [varchar](100) NULL,
- [Emp_Sal] [decimal](10, 2) NULL
- ) ON [PRIMARY]
- GO
- CREATE TYPE Employee AS TABLE
- (
- [Emp_ID] [int] IDENTITY(1,1) NOT NULL,
- [Emp_name] [varchar](100) NULL,
- [Emp_Sal] [decimal](10, 2) NULL
- )
- GO

Humayun Kabir MamunPosted Jan 25, 2016, 10:51 PM
Nice...
Ankur MistryPosted Jan 25, 2016, 10:46 PM
Nice share.
Gowtham KPosted Jan 25, 2016, 9:08 PM
Good One
Yashwant VishwakarmaPosted Jan 25, 2016, 4:55 AM
Nice info, thanks for sharing !!
Mohammed IbrahimPosted Jan 25, 2016, 4:35 AM
nice
Shubham KumarPosted Jan 25, 2016, 4:00 AM
nice share
Debasis SahaPosted Jan 25, 2016, 3:27 AM
Nice..