如何将数据表传递给mvc中的存储过程? [英] How do i pass datatable to stored procedure in mvc?

查看:73
本文介绍了如何将数据表传递给mvc中的存储过程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将2个数据表作为参数传递给我的存储过程。



使用db.Database.ExecuteSqlCommand .....



请帮忙。



我的尝试:



我刚刚创建了2个用户类型表和存储过程来插入记录。

我不知道如何将Datatables作为参数传递。

解决方案

您需要使用Entity Framework将表值参数传递给存储过程。

(您使用ASP.NET MVC并不重要;实体框架和表值参数是要搜索的关键内容。)



这些搜索参数将引导您找到解决方案:

使用实体框架中的表值参数| C#Corner [ ^ ]

  var 参数=  new  SqlParameter(  @ YourParameterName,SqlDbType.Structured); 
parameter.TypeName = dbo.YourTableTypeName;
parameter.Value = YourDataTable;

db.Database.ExecuteSqlCommand( exec dbo.YourStoredProcedure @YourParameterName ,参数);


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.

解决方案

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[^]

var parameter = new SqlParameter("@YourParameterName", SqlDbType.Structured);  
parameter.TypeName = "dbo.YourTableTypeName";  
parameter.Value = YourDataTable;

db.Database.ExecuteSqlCommand("exec dbo.YourStoredProcedure @YourParameterName", parameter); 


这篇关于如何将数据表传递给mvc中的存储过程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆