【问题标题】:Unable to update stored procedure in to 3 tier architecture in code first无法先在代码中将存储过程更新为 3 层架构
【发布时间】:2017-09-06 11:12:45
【问题描述】:

我有一个现有的项目,它被开发成 3 层架构模式。它有 BLL 和 DAL .dll 文件作为参考。

现在我想访问一个已经在 ssms 中创建的新存储过程,以便在这个项目中使用。 我在具有存储过程名称和 BLL 参数的 .cs 文件中创建了一个方法。构建代码,然后尝试从控制器获取特定方法,但控制器没有将我开发的方法获取到 .cs 文件中。

  • 元数据文件:-

    public int AddChapter(string dOCTitleID, string topicalTitleId, string partTitleId, string chapterNumber, string chapterTitles, string parentChapterId);

  • 在 Chapter.cs 文件中创建的方法:

    public int AddChapterSelect(int dOCTitleID, int topicalTitleId, int partTitleId, string chapterNumber, string chapterTitles, int subChapterId)
    {
         return dam.ExecuteDataSetByUpdate("USP_AddChapter", dOCTitleID, topicalTitleId, partTitleId, chapterNumber, chapterTitles, subChapterId);
    
    }
    

    存储过程

    ALTER PROC [dbo].[USP_AddChapter]        
    (        
    @DOCTitleID int,        
    @TopicalTitleID int,        
    @PartTitleID int,        
    @ChapterNumber nvarchar(50),        
    @ChapterTitles nvarchar(max),        
    @SubChapterID int      
    )        
    as        
    begin            
         insert into Chapters(DOCTitleID,TopicalTitleID,PartTitleID,ChapterNumber,ChapterTitles,SubChapterID)        
     values(nullif(@DOCTitleID,0),nullif(@TopicalTitleID,0),nullif(@PartTitleID,0),@ChapterNumber,@ChapterTitles,nullif(@SubChapterID,0))            
    end
    

请帮忙,我如何更新数据库中的 SP 并访问我的控制器。

【问题讨论】:

  • 控制器没有获取那个特定的方法??如果您的方法不存在,那么您的代码将如何构建。如果您在这里谈论的是 SP,请详细说明您面临的错误
  • 先生,这里的情况是 - 1. 已经开发的 SP 工作正常,并且还从 Method 中获取到 Controller。 2. 但是当我创建一个新的SP时我没有找到它。
  • 请在每行代码前添加 4 个空格。它将更具可读性。
  • 好的,先生,我会的。
  • 没有获取方法是什么意思?它会抛出任何错误吗?

标签: c# asp.net .net-4.0 ssms 3-tier


【解决方案1】:

我只是直接从控制器调用存储过程并添加已经实现DataAccessMethod的现有DAL的命名空间。

创建一个DataAccessMethod对象。

这里的步骤 -

  • 添加命名空间-

                       using DAL;
    
  • 创建 DAL 的数据访问方法的对象

             DataAccessMethod dm = new DataAccessMethod();
    
  • 创建调用存储过程的方法

    public int AddChapterSelect(string subchapterNumber, string subchapterTitles, string chapterId) { return dm.ExecuteDataSetByUpdate("USP_AddChapterSelect", subchapterNumber, subchapterTitles, chapterId); }

  • 在我的函数中调用它:

    protected void btnAddChapter_Click(object sender, EventArgs e) { if (ddlSelectDocumentTitle.SelectedItem.Value != "0") { int res = AddChapterSelect(txtSubChapterNumber.Text, txtSubChapterTitle.Text, ddlChapter_Popup.SelectedValue); if (res > 0) { lblSelectMsg.ForeColor = Color.Green; lblSelectMsg.Text = "Record saved successfully"; txtChapterNumber.Text = ""; txtChapterTitle.Text = ""; txtSubChapterNumber.Text = ""; txtSubChapterTitle.Text = ""; Bind_ddlChapter(); } } else { lblSelectMsg.ForeColor = Color.Green; lblSelectMsg.Text = "Please select document title"; } }

谢谢:)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-13
    • 1970-01-01
    相关资源
    最近更新 更多