Click here to Skip to main content
15,891,633 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to pass 2 Datatables to my Stored Procedure as a parameter.

Using db.Database.ExecuteSqlCommand .....

Please help.

What I have tried:

I just have created 2 user type tables and stored procedure to insert record.
I don't know how to pass Datatables as parameters.
Posted
Updated 20-Feb-16 4:32am

1 solution

You need to pass a Table Valued Parameter to your stored procedure using Entity Framework.
(It doesn't matter that you're using ASP.NET MVC; Entity Framework and Table Valued Parameter are the key things to search on.)

Those search parameters will lead you to the solution:
Using Table Valued Parameters in Entity Framework | C# Corner[^]
C#
var parameter = new SqlParameter("@YourParameterName", SqlDbType.Structured);  
parameter.TypeName = "dbo.YourTableTypeName";  
parameter.Value = YourDataTable;

db.Database.ExecuteSqlCommand("exec dbo.YourStoredProcedure @YourParameterName", parameter); 
 
Share this answer
 
Comments
Abrar Kazi 20-Feb-16 12:13pm    
Thanks buddy. I would definitely try this.
Abrar Kazi 22-Feb-16 2:08am    
Perfect solution! Thanks mate.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900