我们如何在ActionResult Asp.net MVC中使用DartaContext.ExecuteCommand()执行存储过程 [英] How can we execute stored procedures using DartaContext.ExecuteCommand() in ActionResult Asp.net MVC

查看:63
本文介绍了我们如何在ActionResult Asp.net MVC中使用DartaContext.ExecuteCommand()执行存储过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

public class StoreController : Controller
    {
        //
        // GET: /Store/
        DataModelDataContext _objdata = new DataModelDataContext();
        Emp_ProcResult _objEmp = new Emp_ProcResult();
        public ActionResult Index()
        {

         var result=   _objdata.ExecuteCommand("Exec Emp_Proc");// Error
         return View(result);
           
            
        }


如果我用这个.一切正常.


if i use this. This is working fine.

public class StoreController : Controller
    {
        //
        // GET: /Store/
        DataModelDataContext _objdata = new DataModelDataContext();
        Emp_ProcResult _objEmp = new Emp_ProcResult();
        public ActionResult Index()
        {

         var result=   _objdata.ExecuteQuery<emp_proc>("select * from Employee");// Working Fine
         return View(result);
           
            
        }


我想知道如何执行存储过程并在视图页面上获取价值?


I want to know how can i execute stored procedure and get value on View Page?

推荐答案

以这种方式执行存储过程比直接使用T-SQL更加棘手.这是有关MSDN的ExecuteQuery方法的文章.在建议中,有一条注释说明了如何使用相同的方法调用存储过程.我认为这会对您有所帮助:

http://msdn.microsoft.com/en-us/library/bb361109 (v = vs.90).aspx [
Executing stored procedures in this manner is a bit more tricky than straight T-SQL. Here is an article on MSDN that talks about the ExecuteQuery method. In the commends, there is a comment that explains how to call a stored procedure using this same method. I think it will be of help to you:

http://msdn.microsoft.com/en-us/library/bb361109(v=vs.90).aspx[^]


好吧,我想知道在MVC中使用存储过程是一种好方法,也就是说,这是正确的还是错误的??
Okay , i want Know that Using Stored Procedures is a gud approach in MVC i.e. this is right or not??


这篇关于我们如何在ActionResult Asp.net MVC中使用DartaContext.ExecuteCommand()执行存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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