我将如何显示此视图页面...请给我示例代码以在MVC asp.net中使用存储过程 [英] How Will i show View Page for this...Please give me sample code to use stored procedure in MVC asp.net

查看:69
本文介绍了我将如何显示此视图页面...请给我示例代码以在MVC asp.net中使用存储过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

public class MyController : Controller
{
    private ISomeRepository _repository;
    
    public MyController()
    {
        // You'd want to use dependency injection here!
        _repository = new SomeRepository();
    }
    
    public ActionResult Index()
    {
        var data = _repository.GetOutstandingInvoices();
        return View(data);
    }
 
}
 
public interface ISomeRepository
{
    DataTable GetOutstandingInvoices();    
}
 
public class SomeRepository : ISomeRepository
{
    public DataTable GetOutstandingInvoices()
    {
        var results = new DataSet();
 
        var connectionString = ConfigurationManager
            .ConnectionStrings["MyDatabase"].ConnectionString;
 
        using (var connection = new SqlConnection(connectionString))
        {
            connection.Open();
            using (var command = new SqlCommand("GetOutstandingInvoices", connection))
            {
                command.CommandType = CommandType.StoredProcedure;
                
                // Add any params? 
                
                var adapter = new SqlDataAdapter(command);
                adapter.Fill(results);
            }
        }   
        
        if (results.Tables.Count > 0)
        {
            return results.Tables[0];
        }
        else
        {
            throw new ApplicationException("No data generated for invoicing");
        }         
    }
}

推荐答案

如何显示此视图页面
通过查看源代码来猜测UI的外观,这有点不可预测..

在MVC asp.net中使用存储过程的示例代码
有关CP的类似问题,请参考答案:
我们可以在asp.net的mvc3应用程序中使用存储过程吗? [ ^ ]

这里还有更多:
ASP.NET MVC:调用存储过程的最佳方法 [ ^ ]
ASP.NET MVC 3模型+存储过程 [ ^ ]

请参阅本教程,该教程具有使用存储过程的完整详细信息 [
How Will i show View Page for this
This is bit unpredictable by seeing source code to guess how the UI look like..

sample code to use stored procedure in MVC asp.net
Please refer answer for similar question on CP:
can we use Stored procedures in mvc3 application in asp.net[^]

Here are some more:
ASP.NET MVC: Best Way To Call Stored Procedure[^]
ASP .NET MVC 3 Models + stored procedures[^]

Please see this tutorial, its having complete details of Using Stored Procedures[^]


这篇关于我将如何显示此视图页面...请给我示例代码以在MVC asp.net中使用存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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