Pass Table Valued Parameter to Stored Procedure

Posts   
 
    
dm.Frank
User
Posts: 21
Joined: 26-Apr-2013
# Posted on: 01-Aug-2016 12:55:28   

As the title suggests, I want to pass table valued parameter which is DataTable from C#. I am using SQLServer 2012.

Here is how I defined Table Valued Parameter in SQL:



Create Type SchoolTableType as Table
(
    SchoolID int primary key,
    SchoolName nvarchar(50),
    LocationID int 
)


Here is the procedure



Create Proc spInsertSchool
@schoolDataTableVariable SchoolTableType readonly
as
begin
    Insert into School 
    Select * from @schoolDataTableVariable
end


Here is how i am calling that stored procedure from C#



DbParameter[] param = new DbParameter[] {  };
adapter.CallActionStoredProcedure("SpInsertSchool", param);

What my question is I dont know how to pass DataTable as parameter to StoredProcedure.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 01-Aug-2016 17:25:18   

This is currently not supported, however it's planned for v5.1

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 26-Jan-2017 10:53:27   

This feature has been postponed to a future date/version.

Frans Bouma | Lead developer LLBLGen Pro
gregsohl
User
Posts: 19
Joined: 20-Mar-2017
# Posted on: 25-Apr-2017 23:29:07   

I'm surprised LLBLGen doesn't already support this. This has been a SQL Server feature since 2008, right? We'd love to be able to use it with LLBLGen, please.

I imagine I can do it manually, with LLBLGen's help, with something like this, right?

dataAccessAdapter.CallActionStoredProcedure("[myDB].[dbo].[mySP]", parameters);
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 26-Apr-2017 10:20:06   

It's not as simple as it looks: the main issue was and is the retrieval of the table shape for generating the proper call code. The table shape is defined separately, and then used by the proc. It was a hassle to merge the table shape into the metadata as it's not used anywhere else, and as this had a low priority we postponed it.

To pass a TVP as a parameter to a stored proc, you have to create a datatable with the proper columns (custom per proc/TVP).

Yes calling CallActionStoredProcedure with the properly setup DbParameter instances should work fine.

Frans Bouma | Lead developer LLBLGen Pro
gregsohl
User
Posts: 19
Joined: 20-Mar-2017
# Posted on: 26-Apr-2017 15:49:03   

Thank you Otis. Our usage should be limited, so CallActionStoredProcedure will suffice for now.

Greg